| Autore |
Messaggio |
gianni.costanzi
|
Thread
Postato:
23 gennaio 2005
Titolo:
Absolute URLs and application root
|
|
|
I want to ask you one thing about the use of absolute URLs in the JSP pages and in the servlets.. Suppose that I have a web application called "webapp" with an index.jsp page in its root.. When I want to forward from a servlet to that page I get a RequestDispatcher giving to it the string "/index.jsp".. Why, if I create a jsp page with a form and in the action field of the form I specify "/index.jsp" when I click on submit I am directed to "http://localhost:8080/index.jsp" (that does not exist) instead of being directed to "http://localhost:8080/webapp/index.jsp"? Is there any way to specify that with the initial "/" I mean the root of the application and not the level in which all the web applications are placed? Why should the servlet and the form behave differently? Perhaps it's only a matter of specifying something in the web.xml..
Thank you!
|
|
|
afogarolli
|
Postato:
24 gennaio 2005
Titolo:
Re: Absolute URLs and application root
|
|
|
If you use RequestDispatcher your example is ok because the url is always relative to the current web application. If you put a reference to a jsp in the html form, the / character always reference to the tomcat root that's why the browser redirects your request to localhost:8080/index.jsp. To make it works you can use an url relative to the html form or a complete url ex. http:/localost:8080/webapp/index.jsp. This is the way the browser manages the links. Bye.
|
|
|
S_andrew
|
Postato:
10 febbraio 2005
Titolo:
Re: Absolute URLs and application root
|
|
|
|
If you are putting some url's to resources into your jsp pages, I suggest you to insert <%= request.getContextPath() %> instead of the name of your web application. Because next time, when your change the application name it will be very difficult to modify all names.
|
|
|
gianni.costanzi
|
Postato:
12 febbraio 2005
Titolo:
Re: Re: Absolute URLs and application root
|
|
|
| S_andrew wrote: | | If you are putting some url's to resources into your jsp pages, I suggest you to insert <%= request.getContextPath() %> instead of the name of your web application. Because next time, when your change the application name it will be very difficult to modify all names. |
Thank you, I used <%= application.getServletContextName() %> because I thought it was not a good idea to put the application name inside the pages (for the reason that you already said)
|
|
|