日期:2014-05-17  浏览次数:20698 次

新手求助大神帮忙!struts2中action的映射问题,纠结了一天了。
最近开始学习struts2和hibernate框架,碰到了问题 如下:
HTTP Status 404 - There is no Action mapped for namespace [/jsp/user] and action name [Userregisteraction] associated with context path [/dz3v].

type Status report

message There is no Action mapped for namespace [/jsp/user] and action name [Userregisteraction] associated with context path [/dz3v].

description The requested resource (There is no Action mapped for namespace [/jsp/user] and action name [Userregisteraction] associated with context path [/dz3v].) is not available.
Apache Tomcat/7.0.29
 大致的意思是说 Action 不能映射到namespace [/jsp/user] 下,我的Action类都放在src/com/da3v/dzaction/文件夹下,我在sruts.xml文件的配置:
<?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="dzaction" extends="struts-default" >

<action name="Userregisteraction" class="com.dz3v.dzaction.Userregisteraction" >
<result name="success">/welcome.jsp</result>
<result name="input">/userregister.jsp</result>
</action>
</package>

</struts>  
jsp代码:
<form action="Userregisteraction" method="post" onsubmit="return reg(this)" >
jsp文件位于/jsp/user下。
浏览器访问:http://localhost:8888/dz3v/jsp/user/userregister.jsp后跳转为:
http://localhost:8888/dz3v/jsp/user/Userregisteraction 
我猜测是namespace 是[/jsp/user],我在jsp代码 和struts.xml配置文件试着加入namespace="/com/dz3v/dzaction/"无效。
我现在搞不懂怎么把我的Userregisteraction映射出来呢?那位神仙开来帮帮我吧,快吐血了都。
ps:我的目录结构图片:

------解决方案--------------------
你少写配置文件了 这个例子对照自己错到那里了


<?xml version= "1.0 " encoding= "UTF-8 " ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN "
"http://struts.apache.org/dtds/struts-2.0.dtd ">

<struts>

<constant name= "struts.enable.DynamicMethodInvocation " value= "false " />
<constant name= "struts.ognl.allowStaticMethodAccess " value= "true " />
<constant name= "struts.devMode " value= "true " />
<constant name= "struts.objectFactory " value= "org.apache.struts2.spring.StrutsSpringObjectFactory "/>

<package name= "default " namespace= "/ " extends= "struts-default ">

<action name= "userLogin " class= "po.UserLoginAction ">
<result> /user/userIndex.jsp </result>
<result name= "input "> /index.jsp </result>
<result name= "admin "> /admin/adminIndex.jsp </result>
</action>
</package>


<!-- Add packages here -->

</struts>
------解决方案--------------------
在struts里面给package配置namespace=“/jsp/user”就可以了
------解决方案--------------------
action请求是自己定义的,是根据你的namespace和配置的action生成的。
如,你定义了一个package ,namespace是/user,那么,所有你在这个package里定义的action
,在访问的时候,地址是/user/配置的action名.action
这个和你的class文件和jsp文件的目录是没有关系的。
------解决方案--------------------
<form action="<%=basePath%>Userregisteraction.action" method="post" onsubmit="return reg(this)" >