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


    一、<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>

     

  • 相关阅读:
    java线程池笔记
    java多线程简单用法
    Java 常用工具类整理
    Linux nohup命令详解
    Java八种基本类型
    isms项目tomcat运行配置
    2017计划
    ES6 Reflect 与 Proxy
    ES6 Map与Set
    ES6 Symbol类型
  • 原文地址:https://www.cnblogs.com/shamgod/p/5243721.html
Copyright © 2020-2023  润新知