experience of struts2
struts中tiles插件中可以定义

<put name="body" value="login.do"/>

但是struts2之后tiles成为一个Apache的独立的项目

在struts2中使用tiles之后 希望使用

<put-attribute name="body" value="login.action" />

但是调试的结果为一直显示

 The requested resource (/struts2/login.action) is not available

甚是无奈, 翻译tiles文档(tiles-2.1.3-bin\tiles-2.1.3\tlddoc) 发现
Tag insertAttribute的解释为:

Inserts the value of an attribute into the page.

This tag can be flexibly used to insert the value of an attribute into a page. As in other usages in Tiles, every attribute can be determined to have a "type", either set explicitly when it was defined, or "computed". If the type is not explicit, then if the attribute value is a valid definition, it will be inserted as such. Otherwise, if it begins with a "/" character, it will be treated as a "template". Finally, if it has not otherwise been assigned a type, it will be treated as a String and included without any special handling.

Example :

  <tiles:insertAttribute name="body" />  


即为 tiles默认将我们的结果判定为字符或者其他已经定义的类型,如若以“/”开始 可查看以此为url的jsp文件
也就是说我们的action对象被认为是文件所以未找到



应该说这个是struts2中filter过滤器再次没起到作用


对此 我们将我们原先的filter进行修改,使其filter的范围更大


 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>R</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
 </filter-mapping>

原先的基础上添加以上红色部分

这个样子就能实现我们的预期的目的


实现tiles2里面无法调用action
解决了tiles2里面呢无法调用struts2中action对象的问题



不指定struts2 , 评论(0) , 阅读(747) , Via 本站原创
Tags: , ,
最近做一个struts升级到struts2的项目

突然发现struts和struts2根本就是有着本质的差别

里面很多的配置都是完全不一样的

struts1中的tiles只算是apache的一个小插件 但是到struts2中tiles已经成为Apache的一个项目来研发,可见其重要性

就研究struts2和tiles的配置我就花了好长时间

下面把我的配置文件发出来,以防以后忘记

web.xml
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]