在使用Struts2开发时,有时需要用redirect 来跟多个参数,然而我们直接?param1=${a}¶m2=${b}。。是会被xml解析异常报错的,如下替换就可以了,
<action name="SectionInfo!*" method="{*}" class="docroad.action.apps.SectionInfo">
<result>/pages/apps/SectionInfo.jsp</result>
<result name="list" type="redirect">/Sections.do?appid=${appid}&pageNo=${pageNo}</result>
</action>
<action name="enterpreinfo" class="preinfoBusinessAction" method="enterPreinfoSub"> <result name="success" type="redirect-action"> showpreinfo?preinfo.order_number=${preinfo.order_number}&preinfo.company_name=${preinfo.company_name} </result> <result name="error" type="redirect"> <param name="location">/error.jsp</param> </result> </action>
多个参数的连接符使用了"&",但XML的语法规范,应该使用"&"代替"&",原理和HTML中的转义相同,开始没有注意,在struts分析配置文件时,总是报出这样的错误
Struts2中正确使用重定向与参数传递
本文介绍了在Struts2框架中如何正确地进行页面重定向并传递多个参数的方法。针对XML配置文件中出现的特殊字符&的转义问题,给出了具体的解决方案,避免了因非法字符导致的配置解析错误。
156

被折叠的 条评论
为什么被折叠?



