"Query String" inside URL segments? - html

Take the example question https://stackoverflow.com/questions/3563957/https-url-path-and-query-string.
As you can see, we have the segment /questions followed by what I'm assuming is the question ID, /3563957. In my head, this would indicate a folder structure like:
.
└── questions/
└── 3563957
However, I can't imagine a directory is being generated for each question. To me, this seems like a query string that is being used as a URL segment. How is this accomplished?

This is accomplished on the server side. When the server sees the request, it likely doesn't treat the url like a directory. This can be accomplished many different ways depending on what you are using for your server.

Related

How do I concatenate 2 strings in Django

I need to show an image of the database, but I need to insert a slash before {{...}} because only then does the file access the static folder. What should I do?
You can do this like recommended in the two comments but actually django coveres this exact usecase. What you are searching is an administration of your static files, the docs are here: https://docs.djangoproject.com/en/1.11/howto/static-files/ .
If you want to have your files organised with the orm, checkout https://docs.djangoproject.com/en/1.11/topics/files/ especially the second code snippet. A File object gives you a name, path and url which should cover all your needs including absolute and relativ paths for your files.

Get the username with GitLab / markdown

I'm a newbie, and maybe I don't have the good keywords for my search.
Here's my question.
I'm trying to generate a md (markdown) file and I want to know if it is possible to get the current username, as i'm inside a gitlab project.
To get an output like
I'm "username"
when reading the markdown file.
Thanks for your explanation !
I'm assuming you are just talking about a markdown file in a GitLab repository. In that case, it's not possible since it's only a static file and the GitLab server doesn't do any processing on it. So there's no way to have it display differently for each user.

Is it possible to retrieve text files content from a parameter and display in HTML?

Say I have a product listing with descriptions. Can I store the descriptions in text files and call them by setting a parameter path in web.xml? Is that even possible? Calling txt file extensions?
It may be a stupid question but I have no clue... Would it slow down the app if I host everything in separate files instead of the database?
Yes, very much so; you are referring to static sites, which may be pre-generated or may be very simple wrapped by jsp. Take a look at static site generators.

save html page from the server by URL with no changes - get the exact copy, the clone

Let's say I have a URL http://example.com/path/to/document.html
That's the html document, the file, that has no external css or js.
If I open it in Google Chrome and save it with Ctrl+S locally, the content is changed. The content of that html file starts with <!-- saved from url= which is not I want at all. I need to get the exact html document, even spaces count.
The second option is to copy it with Ctrl+U (View Source), Select All and paste it into new document, save it and rename it. This is better, however spaces, tabs and end of file will be different depending on what operation system I'm using.
I need the exact copy of that html file - byte to byte.
How to make it?
This is a practical question as I need slightly modify that document.
I'm sorry there is no any source code in my question, but this question is about web developing.
Any ideas?
Thank you.
P.S. Of course that document could be generated by php or whatever, the part of the code can be even extracted from the db, but not in my case. I know that's a plain file.
I'd delete the comment after saving from Chrome, use wget in a linux environment, or open the page as an InputStream in Java. Do all three, run a diff, and if two arrived identical assume that's the file on the server.
Why do you need a byte-for-byte copy of the file on the server anyway, and why can't you ftp the file? There is always the chance that the server will serve different html files depending on your user-agent, but there are other tools which may be better than Chrome for getting your copy and many can spoof a user-agent as well.

Output reformatted text within a file included in a JSP

I have a few HTML files that I'd like to include via tags in my webapp.
Within some of the files, I have pseudo-dynamic code - specially formatted bits of text that, at runtime, I'd like to be resolved to their respective bits of data in a MySQL table.
For instance, the HTML file might include a line that says:
Welcome, [username].
I want this resolved to (via a logged-in user's data):
Welcome, user#domain.com.
This would be simple to do in a JSP file, but requirements dictate that the files will be created by people who know basic HTML, but not JSP. Simple text-tags like this should be easy enough for me to explain to them, however.
I have the code set up to do resolutions like that for strings, but can anyone think of a way to do it across files? I don't actually need to modify the file on disk - just load the content, modify it, and output it w/in the containing JSP file.
I've been playing around with trying to load the files into strings via the apache readFileToString, but I can't figure out how to load files from a specific folder within the webapp's content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.
but I can't figure out how to load files from a specific folder within the webapp's content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.
If those files are located in the webcontent, use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path. This works if the WAR is exploded in the appserver (most does it by default, only Weblogic doesn't do that by default, but this is configureable IIRC). Inside servlets you can obtain the ServletContext by the inherited getServletContext() method.
String relativeWebappURL = "/html/file.html";
String absoluteFilePath = getServletContext().getRealPath(relativeWebappURL);
File file = new File(absoluteFilePath);
// ...
Alternatively, you can put it in the classpath of the webapplication and make use of ClassLoader#getResource():
String relativeClasspathURL = "/html/file.html";
URL absoluteClasspathURL = Thread.currentThread().getContextClassLoader().getResource(relativeClasspathURL);
File file = new File(absoluteClasspathURL.toURI());
// ...
As to the complete picture, I question if you have ever considered an existing templating framework like Freemarker or Velocity to ease all the job?