0

This seems like a pretty basic question but I unfortunately don't know the answer and can't seem to find it.

I'm trying to understand the lifecycle of an initial POST/GET to a Java 6 server running Spring 2.5 on Tomcat 6.

I noticed that for an HttpServletRequest, request.getRequestURL() in a controller returns the original request to which it is mapped (ex. "http://localhost:8080/computers/accessories.html"). That same invocation in the corresponding JSP returns the path to the JSP itself (ex. "http://localhost:8080/WEB-INF/jsp/category.jsp"). I was expecting to see the original HTML request!

Am I missing something?

Stano
  • 353
  • 1
  • 13

1 Answers1

0

This behavior is specified in the api doc:

If this request has been forwarded using RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse), the server path in the reconstructed URL must reflect the path used to obtain the RequestDispatcher, and not the server path specified by the client.

Look at getRequestURI.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I knew I was missing something. Thanks for the quick reply. – Stano Sep 30 '11 at 15:40
  • Came across a thread which also addresses this: http://stackoverflow.com/questions/1256562/java-httpservletrequest-get-url-in-browsers-url-bar – Stano Sep 30 '11 at 17:41