Struts的action问题

本文探讨了Struts2框架中配置文件(struts.xml)包含其他XML文件(item.xml)时出现的URL解析差异问题。作者通过实验发现,这种差异与包含操作有关,而非命名空间导致,并猜测可能是版本问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置文件:struts.xml

XML code

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="q2c"/> <constant name="struts.i18n.encoding" value="UTF-8" /> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.devMode" value="true" /> <constant name="struts.server.static.browserCache" value="false"/> <constant name="struts.configuration.xml.reload" value="true" /> <constant name="struts.ui.theme" value="simple" /> 省略… <include file="com/qtoc/config/item/item.xml"></include> </struts>


item.xml文件

XML code

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> 省略… <package name="item" namespace="/item" extends="qtoc"> <action name="spStyleManageUI*" class="com.qtoc.item.action.style.SpStyleManageAction" method="{1}"> <result>/WEB-INF/base/item/{1}_style.jsp</result> </action> </package> </struts>


在页面上有XXX.Jsp:
<s:url action="spStyleManageUIaddUI" namespace="/item"/>
如果是把item.xml包含在Struts.xml中,当启动tomcat解析XXX.jsp时
<s:url action="spStyleManageUIaddUI" namespace="/item"/>
会被解析成:/item/spStyleManageUIaddUI;jsessionid=37289372937293872893273

如果把:
<action name="spStyleManageUI*" class="com.qtoc.item.action.style.SpStyleManageAction"
method="{1}">
<result>/WEB-INF/base/item/{1}_style.jsp</result>
</action>
直接写在Struts.xml里面,解析出来就是:
/item/spStyleManageUIaddUI
现在还不知道是什么原因,发现后就贴上来了,希望同网友分享,解决原因。
struts2是最新的2.1.8.1
我又测试了一下,跟namespace="/item"没关系,就是<include file="com/qtoc/config/item/item.xml"></include>
包含的问题,但还没测试是不是版本问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值