Possible Duplicate:
How to use relative paths without including the context root name?
In my Tomcat webapps directory, I have a context, app, that contains in its WEB-INFO/classes directory a tree named test, with a bunch of class files under it. app also contains an html file whose purpose is to collect user input and then invoke one of the servlets in the classes/test directory to generate HTML output. The web.xml describing the servlet is as follows:
<servlet>
<servlet-name>foo</servlet-name>
<servlet-class>test.DoIt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>/doit</url-pattern>
</servlet-mapping>
The body of the html file is
<FORM ACTION="/app/doit">
First Parameter: <INPUT TYPE="TEXT" NAME="param1">
<CENTER><INPUT TYPE="SUBMIT"></CENTER>
</FORM>
This all works. But it seems somehow wrong to have to specify the name of the app in the form action of the html file. Is there a way to avoid this, or can someone explain to me why it makes sense that you should have to? Thanks.
If you are disciplined, you don’t have to. Imagine having
/app/form.htmland/app/doitservlet. Since from the browser perspective they are in the same folder, you can simply say:Of course relative paths work as well, e.g. with
/app/pages/form.htmland/app/servlets/doityou can say: