It's quite simple, really, although it has nothing to do with a difference
between JSP's and servlets (since JSP's are compiled into servlets). The
JSP's and servlets both "live" inside a context, here the
"demo"-web-application. Paths within scripting-elements in JSP's or
servlet-methods are (as a rule) interpreted relative to this contxt, so "/"
becomes "/demo/". 
But when you use a form in a JSP, the following request (after the user hits
the submit-button) in fact comes from the client's browser (!), not from
within your application. Therefore, the path is interpreted relative to the
root-path of your Webserver (i.e. Tomcat or maybe Apache).

greetings

Andreas Mohrig
cadooz AG
Osterbekstr. 90b
22083 Hamburg

Email: [EMAIL PROTECTED]
Tel.:  +49.40.271 482-13 
Fax.:  +49.40.271 482-11
Web:   www.cadooz.de

-----Ursprüngliche Nachricht-----
Von: Adam W. Montville [mailto:[EMAIL PROTECTED]]
Gesendet: Dienstag, 13. August 2002 08:01
An: [EMAIL PROTECTED]
Betreff: JSP vs. Servlet Paths


Hi all,

I'm new to this list and really need some help.  Let me frame the scenario:

I have CATALINA_HOME set to C:\jakarta-tomcat-4.0.4\jakarta-tomcat-4.0.4.
The rest of the directory structure (and file locations) is as follows:

CATALINA_HOME
      |
      +-- webapps
             |
             +-- demo
                   |
                   +-- jsp
                   |
                   +-- WEB-INF
                          |
                          +-- classes

The "classes" directory contains MyServlet.class, WEB-INF contains web.xml,
"jsp" contains both SourceJsp.jsp and TargetJsp.jsp.

SourceJsp.jsp displays a submit button, which then calls TargetJsp.jsp,
i.e., it contains the line "<FORM METHOD="POST"
ACTION="/demo/jsp/TargetJsp.jsp">".  I then have a Servlet, MyServlet.java
that also calls TargetJsp.jsp.  MyServlet.java contains the line
"this.getServletContext().getRequestDispatcher("/jsp/TargetJsp.jsp").forward
(req, resp)".

Please pay attention to the path difference between these two calls.
SourceJsp.jsp and MyServlet.java both "invoke" the same TargetJsp.jsp,
however, the paths are different: SourceJsp.jsp = /demo/jsp/TargetJsp.jsp;
MyServlet.java = /jsp/TargetJsp.jsp.

I need to understand why this must be the case.  What is the difference
between a JSP invoking a JSP and a Servlet invoking a JSP with regard to the
paths required for such invocation?

Thank you for your help!  I appreciate it!

Regards,

Adam



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to