struts 中如果配置多个module, 可能有问题, 我调试了struts源码发现确实是问题,
有待于网友们进一步确认.我使用的是struts1.1, 配置了两个module: 缺省: struts-config.xml ,
admin: struts-config-admin.xml
category.jsp
--------------------------------
<frameset rows="*" cols="180,*" frameborder="yes" framespacing="1px" border="0" >
<frame name="menuFrame"
src="../categoryAction.jspx?method=loadAllMenus" scrolling="No"
noresize="noresize" >
<frame name="deatilFrame" src="categoryDetail.jsp" >
----------------------------------
categoryDetail.jsp
----------------------------------
<html:form action="categoryAction.jspx?method=saveCategory" >
... ...
<html:form>
-----------------------------------
struts-config-admin.xml:
------------------------------------
<action
attribute="categoryForm"
input="/product/categoryDetail.jsp"
name="categoryForm"
parameter="method"
path="/categoryAction"
scope="request"
validate="false"
type="com.book.web.struts.action.CategoryAction" >
<forward name="viewMenu" path="/product/categoryMenu.jsp" />
<forward name="succ" path="/product/categoryDetail.jsp" />
</action>
-----------------------------------
以链接的形式访问正确, 直接访问action
http://localhost:8080/promtion/admin/categoryAction.jspx?method=saveCategory
正确.
但把action 放到jsp页面中就出错, http://localhost:8080/promtion/admin/category.jsp
javax.servlet.ServletException: Cannot retrieve mapping for action /categoryAction
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.admin.product.categoryDetail_jsp._jspService(categoryDetail_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /categoryAction
org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:810)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
org.apache.jsp.admin.product.categoryDetail_jsp._jspx_meth_html_form_0(categoryDetail_jsp.java:187)
org.apache.jsp.admin.product.categoryDetail_jsp._jspx_meth_html_html_0(categoryDetail_jsp.java:147)
org.apache.jsp.admin.product.categoryDetail_jsp._jspService(categoryDetail_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我调试了struts 源码发现 刚开始 也能取到module 的name 值为admin, 但在后续处理的时候就把该值丢了,
于是struts只能从struts-config.xml 文件读取,
而不是从struts-config-admin.xml中读取action, 所有就找不到了action, 抛出异常.
struts 1.2 我还有待测试, 不知道是否有同样的问题.?
其它相同问题的网友发言:
原文链接1:http://www.blogjava.net/shaofan/archive/2006/03/01/32974.html
原文链接2:http://202.100.72.44/news/itschool/pro/pro44134.htm
DispatchAction 必须不写execute(... ...)方法, 否则反而有问题,
使用中我发现如果你写了exceute 方法 struts仍然首先调用改excute()方法, 这是即使你配置了 method 参数如
action="abcAction.do?method=load" 也无效, struts 仍然首先执行execute,
故DispatchAction中不要写execute( ... ...) 方法.
jsp 页面提交以后, actionservlet根据配置文件struts-config.xml 中action
的配置, 首先到 reqest 或session 中查找对应的form(action 的attribute 即为form
对象的名称)对象是否存在, 如果不存在, 首先new 一个form对象.
然后调用reset方法设置该form对象的属性;
再从jsp页面取得属性并set bean的属性,
然后再调用validate方法(validate = true),验证出错, 则直接返回到input 页面,正确则调用action的方法进行出来.
posts - 3, comments - 3, trackbacks - 0, articles - 0
Copyright © gong