Struts2 -- No result defined for action action.Register and result success

2024-01-02 04:58

本文主要是介绍Struts2 -- No result defined for action action.Register and result success,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Struts2 – No result defined for action action.Register and result success


BUG
  在跟着官网的例子学习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: sino_crazy_snail@qq.com*/
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.*/@Overridepublic 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_snailEmail: sino_crazy_snail@qq.comDate : 2018-04-02Time : 11:56To 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_snailEmail: sino_crazy_snail@qq.comDate : 2018-04-02Time : 12:07To 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'
}

success

这篇关于Struts2 -- No result defined for action action.Register and result success的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/561394

相关文章

Unable to instantiate Action, goodsTypeAction, defined for 'goodsType_findAdvanced' in namespace '/

报错: Unable to instantiate Action, goodsTypeAction,  defined for 'goodsType_findAdvanced' in namespace '/'goodsTypeAction......... Caused by: java.lang.ClassNotFoundException: goodsTypeAction.......

struts2中的json返回指定的多个参数

要返回指定的多个参数,就必须在struts.xml中的配置如下: <action name="goodsType_*" class="goodsTypeAction" method="{1}"> <!-- 查询商品类别信息==分页 --> <result type="json" name="goodsType_findPgae"> <!--在这一行进行指定,其中lis是一个List集合,但

ORACLE语法-包(package)、存储过程(procedure)、游标(cursor)以及java对Result结果集的处理

陈科肇 示例: 包规范 CREATE OR REPLACE PACKAGE PACK_WMS_YX IS-- Author : CKZ-- Created : 2015/8/28 9:52:29-- Purpose : 同步数据-- Public type declarations,游标 退休订单TYPE retCursor IS REF CURSOR;-- RETURN vi_co_co

struts2的时候

在使用struts2的时候,我们在jsp中经常写这样的代码片段:      学生姓名:            考试名称:            考试分数:         其中studentScores.student.stuName是对应后台action的熟悉,action是这样写的   public class StudentExamAc

用ajax json给后台action传数据要注意的问题

必须要有get和set方法   1 action中定义bean变量,注意写get和set方法 2 js中写ajax方法,传json类型数据 3 配置action在struts2中

使用http-request 属性替代action绑定上传URL

在 Element UI 的 <el-upload> 组件中,如果你需要为上传的 HTTP 请求添加自定义的请求头(例如,为了通过身份验证或满足服务器端的特定要求),你不能直接在 <el-upload> 组件的属性中设置这些请求头。但是,你可以通过 http-request 属性来自定义上传的行为,包括设置请求头。 http-request 属性允许你完全控制上传的行为,包括如何构建请求、发送请

Struts2常用标签总结--转载

Struts2常用标签总结 一 介绍 1.Struts2的作用 Struts2标签库提供了主题、模板支持,极大地简化了视图页面的编写,而且,struts2的主题、模板都提供了很好的扩展性。实现了更好的代码复用。Struts2允许在页面中使用自定义组件,这完全能满足项目中页面显示复杂,多变的需求。 Struts2的标签库有一个巨大的改进之处,struts2标签库的标签不依赖于

解决The valid characters are defined in RFC 7230 and RFC 3986

解决方法: 一、更换低版本的Tomcat;(我选的方案) 二、参考:https://blog.csdn.net/qq_32365919/article/details/82055800

Struts2和Spring整合中出现的问题

今天做了一个Struts2和Spring整合的练习,中间出了一点问题,贴出来供其它人参考。(该文章写于2010年) 代码写好后启动Tomcat服务器时报错: 严重: Exception starting filter struts2java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeExceptio

Result 和 自定义异常 在前后端交互中的作用

Result 和自定义异常在前后端交互中扮演着重要的角色。它们可以帮助我们规范化接口返回值,提高错误处理的可读性和可维护性。 Result的作用 Result通常是一个封装了请求结果的类,它包含了请求的状态码、消息和数据。在前端和后端的交互中,Result的作用主要体现在以下几个方面: 统一返回格式:通过Result类,后端可以将请求的结果统一封装成一个固定的格式返回给前端,这样前端可以更