How to get correct current URL in JSP in Spring webapp

后端 未结 10 604
梦谈多话
梦谈多话 2021-02-03 18:53

I\'m trying to get a correct current URL in JSP in Spring webapp. I\'m trying to use the following fragment in the JSP file:

${pageContext.request.requestURL}


        
相关标签:
10条回答
  • 2021-02-03 19:26

    I used the following in a similar situation. ${currentUrl} can then be Used where needed. Needs core tag library

    <c:url value = "" var = "currentUrl" ></c:url>
    
    0 讨论(0)
  • 2021-02-03 19:27

    You can make Interceptor and set request attribute e.g.

      request.setAttribute("__SELF",request.getRequestURI);
    

    and in jsp

      <form action="${__SELF}" ></form>   
    
    0 讨论(0)
  • 2021-02-03 19:30

    I just found the right answer for your question. The key is using Spring Tags.

    <spring:url value="" />
    

    If you put the value attribute empty, Spring will display the mapping URL set in your @RequestMapping.

    0 讨论(0)
  • 2021-02-03 19:31
    *<% String myURI = request.getAttribute("javax.servlet.forward.request_uri").toString(); %>
                    <% String[] split = myURI.split("/"); %>
                    <% System.out.println("My url is-->"+ myURI
                            + "  My url splitter length --->"+split.length
                            +"last value"+split[4]);%>
    <%--                <jsp:param name="split[4]" value="split[4]" /> --%>
                    <c:set var="orgIdForController" value="<%= split[4] %>" />
                    <a type="button" class="btn btn-default btn-xs"
                        href="${pageContext.request.contextPath}/supplier/add/${orgIdForController}">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                        Add
                    </a>
     - List item*
    
    0 讨论(0)
  • 2021-02-03 19:34

    Anyone who wants to know about other than the reuqest URI, for example a query string, you can check all the names of the variables in the code of RequestDispatcher(of Servlet API 3.1+) interface.

    You can get the query string like this:

    ${requestScope['javax.servlet.forward.query_string']}
    
    0 讨论(0)
  • 2021-02-03 19:40

    In a jsp file:

    request.getAttribute("javax.servlet.forward.request_uri")
    
    0 讨论(0)
提交回复
热议问题