You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Patrick Ruzand <pr...@ilog.fr> on 2001/06/28 15:26:27 UTC

get the request URI in a servlet included by a JSP page

Hello all,

I'm facing a strange problem when trying to get the request URI
in a servlet included by a JSP page.

My jsp page is very simple and looks like :

<html>
<body>
blablabla
<jsp:include src="/servlet/my.package.MyServlet?param=value..."
flush="true"/>
</body>
</html>

where MyServlet is a very simple servlet that only does:

public void doGet(...) {
  System.err.println("requestURI:" + request.getRequestURI());
  System.err.println("path:" + request.getServletPath());
  [...]
}

Using Tomcat 4.0b5, I have the following traces the first time
the connection is made:

requestURI:/myapp/servlet/my.package.MyServlet
path:/servlet/my.package.MyServlet

So the request URI refers to the servlet URI. What I wished.
But... If I open a new connection, the result is a lot different:

requestURI:/myapp/index.jsp
path:/index.jsp


To sum up: for the very first connection, calling request.getRequestURI()
inside my servlet doGet() method gives the servlet URI. For all other
connections opened after, the result is the index.jsp URI.

Using Tomcat 3.3, I have more coherent results : It always gives
the index.jsp URI :-( :

requestURI:/myapp/index.jsp
path:/index.jsp

Then I looked at the code of the
org.apache.catalina.core.ApplicationDispatcher class, and found that the
ctor explicitely changes the request servlet path
to the jsp file URI in the case of a JSP wrapper.
So the fact that it gives index.jsp seems to be wanted.

My question are:
-what should be the right result ?
-is it possible to know the servlet URI from a HttpServletRequest instance
coming from a jsp page ?

Thanks for your help,

Patrick.