Get request URL in JSP which is forwarded by Servlet

后端 未结 8 1302
忘掉有多难
忘掉有多难 2020-11-29 22:27

How can I get request URL in JSP which is forwarded by Servlet?

If I run following code in JSP,

System.out.println(\"servlet path= \" + request.getSe         


        
相关标签:
8条回答
  • 2020-11-29 23:08

    To get the current path from within the JSP file you can simply do one of the following:

    <%= request.getContextPath() %>
    <%= request.getRequestURI() %>
    <%= request.getRequestURL() %>
    
    0 讨论(0)
  • 2020-11-29 23:09

    Same as @axtavt, but you can use also the RequestDispatcher constant.

    request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    
    0 讨论(0)
提交回复
热议问题