简体   繁体   English

如何在URL中自动附加ContextPath?

[英]How can I append ContextPath automatically in URL?

I want to know how to automatically append {pageContext.request.contextPath} on URL when I send URL to controller. 我想知道如何在将URL发送给控制器时自动在URL上附加{pageContext.request.contextPath} I have always added it when I set all urlPath( location.href, img src,a href and so on). 设置所有urlPath(location.href,img src,a href等)时,我总是添加它。 So How should I do if I always don't want to add it on urlPath? 那么,如果我总是不想在urlPath上添加它,该怎么办?

You can use jstl like below: 您可以使用jstl,如下所示:

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<html>
   <head>
      <title><c:url> Tag Example</title>
   </head>

   <body>
      <a href = "<c:url value = "/jsp/index.htm"/>">TEST</a>
   </body>
</html>

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

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