tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Price <epr...@ptc.com>
Subject Re: JSP's in other directories
Date Wed, 05 Feb 2003 17:04:42 GMT


Nicholas J Campbell wrote:
> Hi,
> 	I have a question, I want to be able to access JSP pages that
> are outside of the web-inf directory setup by tomcat…I do not know how
> to do it, obviously. I have Apache 2 installed and use that at my main
> server and then am running tomcat for the purposes of Servlets and JSP’s
> and I want to know what I have to do to make myself be able to access a
> jsp page that is in a directory like c:\site

You should generally be able to refer to resources in your site by using 
a path relative to the context.  For instance, I have the following site 
structure:

/MyApp
  index.jsp
  main.jsp
  others.jsp
  /WEB-INF
   /classes
    /com
     /ptc
      /myapp
       SomeClass.class
       OtherClass.class
       /server
        SomeServlet.class
        OtherServlet.class
   /lib
    somejar.jar

To access one of my JSPs from another JSP, I just use a relative path in 
the "HTML" part of the JSP.  To forward to one of my JSPs from a 
servlet, I use the following line of code:

   String TARGET_JSP = "/main.jsp";

   javax.servlet.ServletContext sc = this.getServletContext();
   javax.servlet.RequestDispatcher rd =
                      sc.getRequestDispatcher(TARGET_JSP);
   rd.forward();

That's one way to do it, even though the servlet is in 
/MyApp/WEB-INF/classes and the JSP is in /MyApp.



Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message