开发者

How to get url path from jsp in Spring MVC framework

开发者 https://www.devze.com 2023-03-19 07:59 出处:网络
To remove the language toggle from the page view(Comfirmation Page) I found this code but it doesn\'t work in Spring MVC

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

0

精彩评论

暂无评论...
验证码 换一张
取 消