简体   繁体   English

如何从 Spring MVC 框架中的 jsp 获取 url 路径

[英]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我找到了这段代码,但它在 Spring MVC 中不起作用

<c:if test="${!fn:contains(pageContext.request.servletPath,'/comfirmation')}">
         //Other Code
</c:if>
  • My actual url is ( ShoppingCart.jsp ).我的实际 url 是( ShoppingCart.jsp )。
  • It is used when /viewCart.htm,/updateCart.htm,/Confirmation.htm ,etc./viewCart.htm,/updateCart.htm,/Confirmation.htm等时使用。
  • 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.因此,用户 go 到/Confirmation.htm ,它也重定向到 ShoppingCart.jsp 但浏览器中的 Z572D4E421E5E6B9BC11D815E8A027112tm.h 路径是 /Confirmation.htm。
  • I want to remove the language toggle when call the /Confirmation.htm in the above mention.我想在上面提到的调用 /Confirmation.htm 时删除语言切换。

Finally, I got it.最后我得到了它。 Here we go这里我们 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.另一种方法是将 url 路径存储在 session 中,因为前面是 controller。

the pageContext.request.servletPath will give you the path of the jsp (and not the url your browser shows). pageContext.request.servletPath将为您提供 jsp 的路径(而不是浏览器显示的 url)。

The request is forwarded to a controller, which returns a path to a view.请求被转发到 controller,它返回视图的路径。 The view ist called using a second internal request使用第二个内部请求调用视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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