-1

May be this is the basic Question. But i am not able to understand how to get it. My browser url is http://testweb/edit.htm'. testweb is context path. This uri is from Spring. I need to get edit.htm which is after context, in my jsp. How to get this. Thank you for the support

Thanks, Santha/

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133
vishnu
  • 567
  • 3
  • 14
  • 34

1 Answers1

2

The HttpServletRequest offers several methods to access (parts of) the request URL, among others the HttpServletRequest#getRequestURI() and #getServletPath().

That said, this job should be done in a Filter or maybe a Servlet rather than a JSP file.


Update: you seem to be using Spring and rather be interested in the request URI which called the forwarded JSP. You can get it as request attribute with the key RequestDispatcher#FORWARD_REQUEST_URI as follows:

String uri = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);

or in JSP EL as follows:

${requestScope['javax.servlet.forward.request_uri']}
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I tried them. Those all methods are retrieving the jsp.Means. If i execute url edit.htm, spring forward to editXXX.jsp. So by executing those methods i am getting editXXX.jsp but not edit.htm – vishnu Sep 07 '10 at 23:25
  • Thank you. I think this is part of Java 6. But i am using below version which is 5. So can i have any other solution in this version. – vishnu Sep 08 '10 at 16:35
  • JSP EL ${requestScope['javax.servlet.forward.request_uri']} is working. Thanks a lot – vishnu Sep 08 '10 at 16:59
  • No, it's not specific to Java 6. It has been in Servlet API all the time. Don't forget to mark the answer accepted if it helped in solving the problem. See also http://stackoverflow.com/faq – BalusC Sep 08 '10 at 17:05
  • Where does `request` in `request.getAttribute` come from? I'm very new at this. If this question makes no sense please just try to point me in the right direction. – Xonatron Jan 30 '12 at 20:59