• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

banghead situation

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I have tomcat 5.0
the context of my web application is : /toddstore
consider the following url :
http://localhost:8080/toddstore/login.html
login.html contains a form to perform a log in operation.
<form action="/loginservlet">
invoking login.html by the browser, I got that the resource is not found.
changing the action to : action="/toddstore/loginservlet">
it works !
why ???
AFAIK, the first approach should work, coz the url is relative to the context path.
any ideas ??
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of <form action="/loginservlet"> put <form action="loginservlet">. The extra / before loginservlet is making it look form the port's root, not context root/loginservlet. Hope this helps.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

coz the url is relative to the context path.



Incorrect. URLs referenced from the HTML pages such as form actions, images, style sheets, script files and so on are server relative. Otherwise, how would the container know which web application to route the request to? The context path must be used in such situations.
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Otherwise, how would the container know which web application to route the request to? The context path must be used in such situations.



If you use this sample code:

<html>
<body>
<form name="testForm" action="TestServlet">
<input type=submit>
</form>

</body>

</html>

The TestServlet is looking from context root on. I don't have to include the context path in my action. If I put a "/" in front of TestServlet then it will look from the server port number, such as localhost:8080/TestServlet, but if I leave off "/", it will look at localhost:8080/context_root/TestServlet. The server handles it.

Thanks,
Jason
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, when you leave off the "/" you get a relative reference. But that reference is relative to the current URL not to the context path. So it could easily break if you move the page to a new URL which doesn't have the same relative base. Not recommended. I always specify a full absolute URL for form actions and other references so that there are no surprises down the line.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If I put a "/" in front of TestServlet then it will look from the server port number



Actually, no it will not. It doesn't work (because the leading slash makes the URL server-relative), but it has nothing to do with the port number.
 
Jason Milliron
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Actually, no it will not. It doesn't work (because the leading slash makes the URL server-relative), but it has nothing to do with the port number.



Your right, i meant what you said but I didn't know the correct wording. Up in the URL it is placed right after the port number, but nothing to do with the port number. Sorry for the confusion.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic