简体   繁体   中英

How to get url path from jsp in Spring MVC framework

To remove the language toggle from the page view(Comfirmation Page)

I found this code but it doesn't work in Spring MVC

<c:if test="${!fn:contains(pageContext.request.servletPath,'/comfirmation')}">
         //Other Code
</c:if>
  • My actual url is ( ShoppingCart.jsp ).
  • It is used when /viewCart.htm,/updateCart.htm,/Confirmation.htm ,etc.
  • So, the user go to the /Confirmation.htm , it also redirect to the ShoppingCart.jsp but the url path in the browser is /Confirmation.htm.
  • I want to remove the language toggle when call the /Confirmation.htm in the above mention.

Finally, I got it. Here we go

<%
    String url=request.getAttribute("javax.servlet.forward.servlet_path").toString();
    if(url.equals("/Confirmation.htm")){    
%>
     //Language Toggle code
<% } %>

I decided to use this. Another way is that storing url path in session since front controller.

the pageContext.request.servletPath will give you the path of the jsp (and not the url your browser shows).

The request is forwarded to a controller, which returns a path to a view. The view ist called using a second internal request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM