experience of struts2
摘要-Aug 17,2009
解决struts2中tiles2中不能调用action的问题
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的解释为:
<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对象的问题
摘要-Aug 13,2009






