使用struts <bean:write> 标签出错解决方案

使用struts的<bean:write name="xxx" property="xxx"/>标签的时候,当对象的属性值为int,long,double的时候,会报出如下的错误:
org.apache.jasper.JasperException: Cannot find message resources under key org.apache.struts.action.MESSAGE

 

解决的方法有两种
   1. 在struts-config.xml 文件中添加
    <message-resources parameter="ApplicationResources"/>

例如

<struts-config>
    <form-beans>
    </form-beans>
    <action-mappings>
        <action path="/studentList" type="com.mose.action.PaginationAction" >
            <forward name="success" path="/studentList.jsp"></forward>
        </action>
    </action-mappings>
    <message-resources parameter="ApplicationResources"/>
</struts-config>

ApplicationResources.properties位于src目录下

 

    2. 利用<bean:write>的format属性,加上一个format="#" 属性
例:<bean:write name="student1" property="score" format="#">

 

 

附:<bean:write>的用法

1. 首先要想使用struts的标签库,则必须在jsp中指定所使用的标签库地uri和prefix,即标签库的标准

<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>

 

2. <bean:write name="object">相当于<%=request.getAttribute("object")%>

 

3.  bean:write常用的属性有如下几个:

     name,用来指定属性的名字

     filter,用来指定是否屏蔽到属性值的HTML格式

     property,用来指定name所代表的对象的属性名字

     format,用来指定显示的时间,数字,日期等的格式

 

例子一:

     某处设置了request.setAttribute("hello","hello world"); 则在某个jsp页面中,用struts的write标签取出并显示的方式如下:

     <bean:write name="hello"/>,则页面上显示出hello world。

 

例子二:

     设置了request.setAttribute("message","<font color='red>欢迎你</font>");

     <bean:write name="message" filter="false"/>,则页面上显示出红色的欢迎你。

     如果filter属性不设置,则默认为true,那么显示出的内容就为<font color='red>欢迎你</font>。

 

例子三:

     某处设置了request.setAttribute("date",new Date());

     <bean:write name=“date”/>,此为默认的显示方法,显示出的时间为:Fri Mar 28 15:04:21 CST 2008

     <bean:write name=“date” format="yyyy-MM-dd HH:mm:ss"/>,此为自己指定日期的显示格式,显示出的时间为2008-3-28 15:04:21

 

例子四:

     某处设置了request.setAttribute("n",“1223333.333”);

     则在某个jsp页面中,用struts的write标签取出并按指定方式显示数字的方法如下:

     <bean:write name=“n”/>,此为默认的显示方法,显示出的数字位1223333.333

     <bean:write name=“n” format="###,###.####"/>,此为自己指定数字的显示格式,显示出的时间为1,223,333.333

     如果希望小数点后的不足四位时,缺位补0,则应

     <bean:write name=“n” format="###,###.0000"/>,此为自己指定数字的显示格式,显示出的时间为1,223,333.3330

例子五:

     假如有User类和Groupe类,User类有属性名字userName,年龄age,性别sex和所属的Groupe,Groupe类有属性组名groupeName,并均具有相应的get和set方

     则在某个jsp页面中,用struts的write标签取出并按指定方式显示结构体的方法如下:

     用户名:<input type="text" value='<bean:write name=“user” property="userName"/>'>

     年龄:<input type="text" value='<bean:write name=“user” property="age"/>'>

     性别:<input type="text" value='<bean:write name=“user” property="sex"/>'>

     组名:<input type="text" value='<bean:write name=“user” property="groupe.groupeName"/>'>

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值