我是Struts2的新手,我跟随http://viralpatel.net/blogs/2010/01/tutorial-struts2-hibernate-example-eclipse.html制作Struts2项目,但我收到错误:HTTP状态404 - 没有映射名称空间/动作名称添加的动作。我正在“Netbeans 6.8”中创建项目。我收到错误的网址格式http://localhost:8080/StrutsTest/add
我的日志:
WARNING: No configuration found for the specified action: 'add' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
WARNING: No configuration found for the specified action: 'add' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
WARNING: Could not find action or result
There is no Action mapped for namespace / and action name add. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
答案 0 :(得分:1)
对于仍然无法解决上述错误的那些人。这就是我为我所做的工作。在呈现表单的jsp页面中,在表单标签上,我只包括了所引用的表单操作名称所在的包的名称空间,例如:
struts.xml(这只是我的struts.xml配置的一小部分)
$applicantresponse = json_decode($applicantresponse);
$link = $applicantresponse->links->link1;
echo json_encode($link);
注意::操作名称是 update ,它位于 / user 名称空间中。
profile.jsp->此表单会产生上述错误
此代码(当我使用它时)产生上述错误,完全是因为我没有包括名称空间属性
<package name="user" namespace="/user" extends="struts-default">
<action name="update" class="actionbean.UserProfileUpdate">
<result name="error">pages/error.jsp</result>
<result name="success" type="redirect">pages/profile.jsp</result>
</action>
</package>
profile.jsp->(此表单将按预期运行)
<form action="update" method="post">
.....
[ other codes ]
</form>
请注意:我不确定为什么该解决方案对我有用,原因是因为在我提供此信息时,我的Web应用程序中有几种表单,因此我不必以除此更新形式以外的任何其他形式执行此操作。
产品版本:NetBeans IDE 8.2(内部版本201705191307)
更新:NetBeans IDE已更新为版本NetBeans 8.2补丁2
Java:1.8.0_161; Java HotSpot(TM)64位服务器VM 25.161-b12
Strut:Strut 2核心2.3.15
祝你好运。
答案 1 :(得分:0)
请复制你的struts.xml文件,这将有助于理解。我可以从你的日志中找到的是你在xml文件中做错了配置,或者你已经在xml中定义了一个尚未定义的动作