Struts2 -- No result defined for action action.Register and result success
程序员文章站
2022-05-24 09:16:47
...
Struts2 – No result defined for action action.Register and result success
在跟着官网的例子学习Struts 2框架的时候遇到了个问题:No result defined for action action.Register and result success.最后发现是struts.xml里 package的namespace
的问题。解决方法在struts.xml的注释里说明了。
Person.java:
package action;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import model.Person;
/**
* Create by sino_crazy_snail on 2018-04-02
* Email: [email protected]
*/
public class Register extends ActionSupport {
private Person person;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
/**
* A default implementation that does nothing an returns "success".
* <p>
* <p>
* Subclasses should override this method to provide their business logic.
* </p>
* <p>
* <p>
* See also {@link Action#execute()}.
* </p>
*
* @return returns {@link #SUCCESS}
* @throws Exception can be thrown by subclasses.
*/
@Override
public String execute() throws Exception {
return SUCCESS;
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.convention.classes.reload" value="true"/>
<!--换成"<package name="hellodemo" namespace="/" extends="struts-default">"就可以正常运行了-->
<package name="hellodemo" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="register" class="action.Register" method="execute">
<result name="success">/thankyou.jsp</result>
</action>
</package>
</struts>
index.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Hello_World Application - Welcome</title>
</head>
<body>
<h1>Welcome To Struts 2!</h1>
<p><a href="register.jsp">Please register</a> for our prize drawing. </p>
</body>
</html>
register.jsp
<%--
User : sino_crazy_snail
Email: [email protected]
Date : 2018-04-02
Time : 11:56
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Register</title>
</head>
<body>
<h3>Register for a prize by completing this form.</h3>
<s:form action="register">
<s:textfield name="person.firstName" label="First Name: "/>
<s:textfield name="person.lastName" label="Last Name: "/>
<s:textfield name="person.email" label="Email: "/>
<s:textfield name="person.age" label="Age: "/>
<s:submit value="Submit"/>
</s:form>
</body>
</html>
thankyou.jsp
<%--
User : sino_crazy_snail
Email: [email protected]
Date : 2018-04-02
Time : 12:07
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Thank You</title>
</head>
<body>
<h3>Thank you for registering for a prize.</h3>
<p>Your registration information: <s:property value="person"/> </p>
<p><a href="<s:url action='index'/>">Return to home page</a> </p>
</body>
</html>
build.gradle:
group 'sino_crazy_snail'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
buildscript {
ext.struts2_version="2.5.16"
ext.log4j2_version="2.11.0"
}
repositories {
mavenCentral()
}
dependencies {
compile "org.apache.struts:struts2-core:${struts2_version}"
compile "org.apache.struts:struts2-convention-plugin:${struts2_version}"
compile "org.apache.logging.log4j:log4j-core:${log4j2_version}"
compile "org.apache.logging.log4j:log4j-api:${log4j2_version}"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
上一篇: Bean实体类转换
下一篇: 深度优先搜索与广度优先搜索区别和案例
推荐阅读
-
No result defined for action and result input - action
-
No result defined for action and result input - action
-
struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)(转载)
-
struts2错误:HTTP Status 404 - No result defined for action xxx and result error
-
Struts2报错:HTTP Status 404 - No result defined for action and result input
-
No result defined for action com.jmq.java.action.BookAction and result success 解决struts2问题
-
2010.09.26———struts2 404 No result defined for action
-
struts2中 No result defined for action
-
struts2的严重问题 No result defined for action ... and
-
Struts2框架后台接收参数乱码问题,No result defined for action action.XxxAction and result error`