简体   繁体   English

春天PetClinic <spring:url …/> 编码非常url

[英]Spring PetClinic <spring:url …/> encoding for very url

I am implementing the Spring Pet Clinic Sample project given here 我正在实施这里给出的Spring Pet Clinic Sample项目

Implementation here 在这里实施

In the home page all the urls are encoded by <spring:url /> tag. 在主页中,所有URL都由<spring:url />标记编码。 I just want to confirm that is it a good programming practice to encode the links, even the simple navigation urls by the spring:url tag or is it done for a specific reason?. 我只想确认编译链接是一个很好的编程习惯,甚至是spring:url标签的简单导航网址,还是出于某种特定原因?

Yes, it's a good practice. 是的,这是一个很好的做法。 That tag is a Spring JSP tag for creating URLs with enhancements for JSTL c:url . 该标记是一个Spring JSP标记,用于创建具有JSTL c:url增强功能的c:url <c:url> tag is used to create a url and it is helpful in the case when cookies is turned off by the client, and you would be required to rewrite URLs that will be returned from a jsp page. <c:url>标记用于创建URL,如果客户端关闭cookie,则会有所帮助,并且您需要重写将从jsp页面返回的URL。 The rewritten URL will encode the session ID if necessary to provide persistent sessions. 如有必要,重写的URL将对会话ID进行编码以提供持久会话。

For example, your URL will be displayed as: 例如,您的网址将显示为:

<c:url value="a.jsp">

/context/a.jsp // when cookies is enabled
/context/a.jsp;jsessionid=B01F432.... // when cookie is disabled

This way, the servlet container can track the user requests. 这样,servlet容器可以跟踪用户请求。 Another important thing is that c:url will prefix the context root, so you don't need to write your root context prefix everywhere. 另一个重要的事情是c:url将为上下文根添加前缀,因此您无需在任何地方编写根上下文前缀。

Like I said, <spring:url> contains some enhancements over JSTL like encoded URI template variables for example. 就像我说的那样, <spring:url>包含一些JSTL的增强功能,比如编码的URI模板变量。

<spring:url value="/url/path/{variableName}">
   <spring:param name="variableName" value="more than JSTL c:url" />
 </spring:url>

Results in: /currentApplicationContext/url/path/more%20than%20JSTL%20c%3Aurl 结果:/ currentApplicationContext / url / path / more%20than%20JSTL%20c%3Aurl

See more details in here: http://docs.spring.io/spring/docs/3.1.4.RELEASE/javadoc-api/org/springframework/web/servlet/tags/UrlTag.html 请在此处查看更多详细信息: http//docs.spring.io/spring/docs/3.1.4.RELEASE/javadoc-api/org/springframework/web/servlet/tags/UrlTag.html

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

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