Regarding the Action Mapping in Struts2 - There is no Action mapped(关于 Struts2 中的动作映射 - 没有动作映射)
问题描述
我正在尝试运行我的 struts 应用程序,但我收到错误操作未映射我已经看到命名空间是正确的,但仍然收到错误?
I am trying to run my struts application but I am getting a error action is not mapped I have seen the namespace it is correct but still getting the error?
struts.xml
:
<?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.devMode" value="false" />
<include file="register.xml"/>
<!-- Add packages here -->
</struts>
还有我的register.xml
:
<?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>
<package name="register" namespace="/" extends="struts-default">
<action name="Register" class="com.struts2.RegisterAction">
<result name="input">/register.jsp</result>
<result type="redirectAction">register.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
我正在验证我的注册页面和验证 XML,如下所示
I am validating my register page and the validation XML as follows
RegisterAction-validation.xml:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">6</param>
<param name="trim">true</param>
<message key="requiredpassword"/>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="email">
<message key="requiredemail"/>
</field-validator>
</field>
<field name="gender">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="postalcode">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[^d*$]]></param>
<message key="requiredinteger"/>
</field-validator>
</field>
</validators>
而我的register.jsp
如下:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Validation Struts page</title>
<s:head/>
</head>
<body>
<s:form action="Register">
<s:textfield key="username"/>
<s:password key="password" />
<s:textfield key="email" />
<s:select headerKey="" headerValue="Select Gender"
key="gender" list="#{'M':'Male','F':'Female'}" />
<s:textfield key="postalcode" />
<s:submit/>
</s:form>
</body>
</html>
我的项目结构如下:
Strutsvalidation
--src-->
com.struts2(package)-->
register.xml,
registeraction-validation.xml,
javaclasses,
struts.xml
--webcontent-->
web-inf-->
web.xml
register.jsp(in web content)
我收到如下错误?
There is no Action mapped for action name Register. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
推荐答案
这个配置错误
<result type="redirectAction">register.jsp</result>
使用
<result>/register.jsp</result>
redirectAction
结果应该用于重定向到用于定位的动作.
The redirectAction
result should be used to redirect to the action, which name is used for location.
异常来自您尝试提交时的 s:form
标记.Register
动作实际上封装在命名空间 /
中.这不是默认命名空间,因此应该在 s:form 标签上使用.
The exception comes from the s:form
tag when you tried to submit it. The action Register
actually packaged in namespace /
. This not a default namespace and therefore should be used on the s:form tag.
<s:form namespace="/" action="Register">
这篇关于关于 Struts2 中的动作映射 - 没有动作映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:关于 Struts2 中的动作映射 - 没有动作映射
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01