struts-cookbook-1.3.10 示例文件学习总结

获取MessageResource 中的值

<bean:message key="button.submit" /> 获得 MessageResources 文件中的值

 

是否原样输出HTML 代码

<bean:write name="simpleForm" property="message" filter="false"/>filter 表示是否转译成 HTML 代码

 

如何判断用户是否点击<html:cancel>

FormAction 当中,

if (isCancelled(request)) {

            return mapping.findForward("home");

        }

 

多选下拉菜单列表

<html:select property="fruit3" size="7" multiple="true">--multiple 可是只为是否为多选,对应的属性通常是 String[] 数组

<form-property name="fruit1" type="java.lang.String" initial="Pear" />

            <form-property name="fruit2" type="java.lang.String" initial="Apple" />--initial 可设置默认值

            <form-property name="fruit3" type="java.lang.String[]" initial="Banana Orange" />-- 空格分隔多选值

 

<bean:write> 的使用

<bean:write name="example" property="doubleValue" format="$0,000.00"/>

<bean:write name="example" property="floatValue" formatKey="format.currency"/>

<bean:write name="example" property="dateValue" format="MMM d yyyy '@' HH:mm"/>

<bean:write name="example" property="dateValue" formatKey="format.date"/>

<bean:write name="example" property="list[2]" />

<bean:write name="example" property="array[3]" />

<bean:write name="example" property="nested.stringValue"/>

 

<logic:present> 的使用

<logic:present cookie="JSESSIONID">

       <p>Session cookie is present.</p>

</logic:present>

logic:present logic:empty 的区别, logic:empty 不仅判断是否为 null ,而且判断集合是否有值,是否为空字符串等,而 logic:present 只判断是否为 null ,是否有内存空间

 

判断是否变量的值是否与指定值相等

<logic:match name="stringValue" value="world">

       <p>stringValue matches 'world'</p>

</logic:match>

 

当没有MessageResources 资源时输出

<logic:messagesNotPresent message="true">

       <p>There are no messages</p>

</logic:messagesNotPresent>

 

Struts 中的跳转方法

<a href="../../processLinks.do">Link using HTML &lt;a&gt; tag</a>-- 可以使用 a 标记

<html:link page="/processLinks.do">Link using page attribute</html:link>-- 也可以使用 formAction Path.do

<html:link action="linksAction">Link using action attribute</html:link>

<html:link action="linksAction" anchor="test">Link to an anchor</html:link>-- 也可以指定跳转页的锚点

 

<h2>Links with Parameters</h2>

<bean:define id="myColor" value="red"/>

<ul>

  <li><html:link action="linksAction?color=blue">Hardcoded parameter</html:link></li>-- 可以带参数

  <li><html:link action="linksAction" paramId="color" paramName="myColor">Dynamic parameter</html:link></li>-- 可以使用变量

  <li><html:link action="linksAction" paramId="msg" paramName="testBean" paramProperty="stringValue">Dynamic parameter from a bean property</html:link></li>-- 可以使用 FormBean 中的信息

  <li><html:link action="linksAction" name="parms">Multiple dynamic parameters from a Map</html:link></li>-- 可以从一个集合中读取

  <li>

    <html:link action="linksAction" name="parms">

      Dynamic parameters from &lt;html:param&gt;

      <html:param name="buybefore" value="Tomorrow" /> ·

      <html:param name="shippedfrom" value="New York" />

    </html:link>

  </li>

</ul>

 

<html:rewrite> 作用

输出 a 标记中的 URI

 

MessageResources 中的值设定参数

MessageResources

# -- messages --

message.detail={0}

message.example.simple=This is a simple message.

message.example.replaceable=This is <strong>{0}</strong> message with <strong>{1}</strong> parameters.

message.welcome=Welcome to the examples page.

 

Jsp:

<h3>Messages</h3>

<p><bean:message key="message.example.simple"/></p>

<p><bean:message key="message.example.replaceable" arg0="a slightly more complex" arg1="2 replaceable" /></p>

<p><bean:message key="message.example.replaceable" arg0="the same template" arg1="different" /></p>

效果:

Messages

This is a simple message.

This is a slightly more complex message with 2 replaceable parameters.

This is the same template message with different parameters.

 

指定语言

String language = request.getParameter("language");

String country = request.getParameter("country");

 

if ((language != null && language.length() > 0)

    && (country != null && country.length() > 0)) {

    locale = new java.util.Locale(language, country);

} else if (language != null && language.length() > 0) {

    locale = new java.util.Locale(language, "");

}

 

//Save locale

session.setAttribute(Globals.LOCALE_KEY, locale);

 

 

action-mapping 通配符的配置

<action-mappings>

  <action path="/Prepare*" forward="/jsp/Wildcard/{1}.jsp" />

  <action path="/Source*" forward="/jsp/{1}/Source.jsp" />

  <action path="/Wildcard*" forward="/jsp/Wildcard/MatchAny.jsp" />

  <action path="/Wildcard-Not" forward="/jsp/Wildcard/MatchOne.jsp" />

</action-mappings>

当同时出现符合通配符与完全匹配的规则时,使用完全匹配规则

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值