首页 > 编程语言 > 详细

SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-004- <s:url>、<s:escapeBody>标签

时间:2016-03-05 00:15:47      阅读:370      评论:0      收藏:0      [点我收藏+]

一、<s:url>

<s:url>可以直接生成一个url或url变量,它会在href的基础上加上应用context

1.

<a href="<s:url href="/spitter/register" />">Register</a>

如果应用的context是“spittr”,则会转换为

<a href="/spittr/spitter/register">Register</a>

 

2.生成url变量

<s:url href="/spitter/register" var="registerUrl" />
<a href="${registerUrl}">Register</a>

 

3.可以指定作用域application、session、request,默认是page

<s:url href="/spitter/register" var="registerUrl" scope="request" />

 

4.<s:url>可以做JSTL的<c:url>不能做的,给url加参数

1 <s:url href="/spittles" var="spittlesUrl">
2     <s:param name="max" value="60" />
3     <s:param name="count" value="20" />
4 </s:url>

 

5.用占位符实现 path parameter的url

<s:url href="/spitter/{username}" var="spitterUrl">
    <s:param name="username" value="jbauer" />
</s:url>

参数名字若匹配不到占位符,则会变以query parameter

 

6.

1 <s:url value="/spittles" htmlEscape="true">
2     <s:param name="max" value="60" />
3     <s:param name="count" value="20" />
4 </s:url>

This results in the URL being rendered like this:

/spitter/spittles?max=60&amp;count=20

 

7.若要在javascript中使用所定义变量

1 <s:url value="/spittles" var="spittlesJSUrl" javaScriptEscape="true">
2     <s:param name="max" value="60" />
3     <s:param name="count" value="20" />
4 </s:url>

 

8.

<script>
  var spittlesUrl = "${spittlesJSUrl}"
</script>

This renders the following to the response:

<script>
  var spittlesUrl = "\/spitter\/spittles?max=60&count=20"
</script>

 

二、<s:escapeBody>

1.在html中显示"<"和">"要分别转换为&lt;和&gt;,否则会被当成html标签的结束和开始标签

<s:escapeBody htmlEscape="true">
    <h1>Hello</h1>
</s:escapeBody>

This renders the following to the body of the response:

&lt;h1&gt;Hello&lt;/h1&gt;

 

2.The <s:escapeBody> tag also supports JavaScript escaping with the javaScriptEscape attribute:

<s:escapeBody javaScriptEscape="true">
    <h1>Hello</h1>
</s:escapeBody>

 

 

SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-004- <s:url>、<s:escapeBody>标签

原文:http://www.cnblogs.com/shamgod/p/5243721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!