struts 多module中 Cannot retrieve mapping for action

Posted on 2006-04-07 20:56 gong 阅读(3530) 评论(2)  编辑  收藏 所属分类: struts
  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

Feedback

# re: struts 多module中 Cannot retrieve mapping for action   回复  更多评论   

2006-04-07 21:18 by dudu
你的三篇文章不合适发表在首页, 应该放在新手区!

# re: struts 多module中 Cannot retrieve mapping for action [未登录]  回复  更多评论   

2011-04-07 15:45 by aa
不是有问题,而是程序运行过程中只识别并加载名为struts-config.xml的文件,其它的都识别不了, 如果配置多个的话必须在web.xml声明才可以正常使用。<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml,/WEB-INF/struts-config-admin.xml</param-value> <!--这里可以添加多个自己定义的文件-->
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
这样的话就可以正常使用了。

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 3, comments - 3, trackbacks - 0, articles - 0

Copyright © gong