struts2自定义标签

Recently while working on a Struts 2 project, I got a strange error message No result defined for action and result input.

最近,在处理Struts 2项目时,我收到一条奇怪的错误消息: No result defined for action and result input

Struts2 –没有为动作和结果输入定义结果 (Struts2 – No result defined for action and result input)

Let’s look at a simple scenario where we get the error message “No result defined for action and result input”.

让我们看一个简单的场景,在该场景中,我们将显示错误消息“没有为操作和结果输入定义结果”。

My project had a simple JSP page like below.

我的项目有一个简单的JSP页面,如下所示。

login.jsp

login.jsp

<%@ page language="java" contentType="text/html; charset=US-ASCII"pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<%-- Using Struts2 Tags in JSP --%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Login Page</title>
</head>
<body>
<h3>Welcome User, please login below</h3>
<s:form action="login"><s:textfield name="name" label="User Name"></s:textfield><s:textfield name="pwd" label="Password" type="password"></s:textfield><s:submit value="Login"></s:submit>
</s:form>
</body>
</html>

And corresponding action class as:

并对应的动作类为:

LoginAction.java

LoginAction.java

package com.journaldev.struts2.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {@Overridepublic String execute(){//Some complex business logicreturn SUCCESS;}@Overridepublic void validate(){if("".equals(getName())){addFieldError("name", "UserName can't be empty");}if("".equals(getPwd())){addFieldError("pwd", "Password can't be empty");}}//Java Bean to hold the form parametersprivate String name;private String pwd;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}
}

My struts 2 configuration file was like below.

我的struts 2配置文件如下所示。

struts.xml

struts.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""https://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.convention.result.path" value="/"></constant>
<package name="user" extends="struts-default"><action name="home"><result>/login.jsp</result></action><action name="login" class="com.journaldev.struts2.action.LoginAction"><result name="SUCCESS">/welcome.jsp</result><result name="ERROR">/error.jsp</result></action></package></struts>

Everything looked fine and when login action will be invoked, LoginAction will take care of it. Incase of success, welcome.jsp will be sent as response or error.jsp incase of any errors.

一切看起来都很好,并且在调用登录操作时,LoginAction将进行处理。 如果成功,将在任何错误的情况下将welcome.jsp作为响应或error.jsp发送。

But whenever I tried to invoke login action without passing username or password values, I get 404 error and browser response as:

但是,每当我尝试调用登录操作而不传递用户名或密码值时,都会收到404错误和浏览器响应,如下所示:

No result defined for action com.journaldev.struts2.action.LoginAction and result input

No result defined for action com.journaldev.struts2.action.LoginAction and result input

And in server logs, I was getting following exception stack trace:

在服务器日志中,我得到以下异常堆栈跟踪:

Sep 14, 2013 11:40:25 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Exception occurred during processing request: No result defined for action com.journaldev.struts2.action.LoginAction and result input
No result defined for action com.journaldev.struts2.action.LoginAction and result inputat com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)

修复–没有为操作和结果输入定义结果 (Fix – No result defined for action and result input)

I was clueless for sometime as what is going on, then I looked at the message and it says that “no result is defined for input“. So I modified my login action like below.

一段时间以来,我一无所知,然后查看了消息,并说“ input未定义结果”。 因此,我修改了我的登录操作,如下所示。

<action name="login" class="com.journaldev.struts2.action.LoginAction"><result name="SUCCESS">/welcome.jsp</result><result name="ERROR">/error.jsp</result><result name="input">/login.jsp</result>
</action>

This simple change solved the issue and I was getting login.jsp page as response with error message set in the validate() method of LoginAction.

这个简单的更改解决了该问题,我得到了Login.jsp页面作为响应,并在LoginAction的validate()方法中设置了错误消息。

The reason is that “input” is the default result returned by Struts 2 whenever there is a problem with validating the parameters passed to an action.

原因是,当验证传递给操作的参数有问题时,“输入”是Struts 2返回的默认结果。

I hope this quick solution will save someone’s time when working with Struts 2 and using form fields validation.

我希望这种快速解决方案可以节省使用Struts 2和使用表单域验证的时间。

翻译自: https://www.journaldev.com/2164/struts-2-no-result-defined-for-action-and-result-input

struts2自定义标签

struts2自定义标签_Struts 2 –没有为动作和结果输入定义结果相关推荐

  1. [JavaWeb基础] 012.Struts2 自定义标签使用

    在做开发中,我们会把一些比较经常使用到的代码封装起来,这样可以加快开发的速度和减少错误,并且在修改bug可以一次修改多次修复.那么在前端页面上,如果我们要经常用到公用的显示功能,并涉及到服务端逻辑操作 ...

  2. Struts2自定义标签——示例

    自定义Button功能描述: <tangs:button  items="apple,orange,banana"/> 解析后为: <input  type=&q ...

  3. Struts2自定义标签(template)——示例

    来源:http://www.blogjava.net/natlive/archive/2009/05/21/271890.html Struts2 的UITag原理: Struts2 UITag分三部 ...

  4. html5创建自定义标签,在html中创建自定义标签

    创建并使用自定义标签 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),本篇介绍使用 CustomElem ...

  5. FreeMarker自定义标签编写

    一.freemarker 实现自定义标签的方法 : 使用  <macro></macro>  宏定定义标签 实现  TemplateDirectiveModel的 execut ...

  6. Struts2自定义类型转换器、自定义拦截器和用户输入数据的验证

    一.自定义类型转换器 1.编写一个类,继承com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter 2.覆盖掉其中的public Obj ...

  7. struts2数据库操作_Struts 2操作错误和操作消息

    struts2数据库操作 Struts 2 provide a lot of custom tags for development and we have already looked into D ...

  8. JSP标签:jsp内置标签、jstl标签、自定义标签

     一.jsp标签的分类: 1)内置标签(动作标签): 不需要在jsp页面导入标签 2)jstl标签: 需要在jsp页面中导入标签 3)自定义标签 : 开发者自行定义,需要在jsp页面导入标签    1 ...

  9. Java-Web JSTL标签库、自定义标签库和MVC设计模式

    目录 一.JSTL标签库 1.什么是JSTL 2.JSTL标签库 3.使用taglib指令导入标签库 4.core标签库常用标签 (1)out和set (2)remove (3)url (4)if ( ...

最新文章

  1. 海思3559A上编译LIVE555源码操作步骤
  2. java c s 与b s架构结合使用_Java技术学习笔记:C/S 与B/S 区别
  3. 华为VC首次出手:投资2家半导体公司,带火5G建材“碳化硅”
  4. 关于 ESP,EBP,EIP
  5. 直播预告丨告别后知后觉的指标波动,神策智能预警分析直播来袭
  6. C# 与 LUA 的经验对比
  7. (Mysql)连接问题之1130
  8. TMDS——最小化传输差分信号及其协议
  9. 科大讯飞 jason word_2019科大讯飞全球1024开发者节开幕啦
  10. 探索比特币源码7-哈希
  11. cad监控图标_干货!多种不同环境的无线视频监控系统拓扑图
  12. c 实现走迷宫流程图_c语言迷宫问题程序功能介绍.设计思路.数据结构设计及用法说明程序结构(流程图).各模块的功能及程序说明....
  13. python rarfile不支持unicode_python – zipfile提取时的unicode错误
  14. 2023长安大学物流管理专硕考研成功经验分享
  15. 用xshell7和xftp7连接虚拟机CentOS7.6的步骤
  16. 硬刚Hive | 4万字基础调优面试小总结
  17. esayExcel自定义注解导出表头批注
  18. CTF Blind pwn题型学习笔记
  19. 从循环神经网络到卷积神经网络
  20. Gmail和Orkut邀请自助发送[共享]

热门文章

  1. [凯立德]2013.12.17凯立德发布秋季版(2F21J0E)最新增量包SP1
  2. 容易忽视但是功能灰常强大的Java API(二. 读写对象)
  3. Java匹马行天下之学编程的起点——走进编程的殿堂
  4. Struts2(一)之认识struts2
  5. Ubuntu图标变成问号
  6. mysql交互式连接非交互式连接
  7. hdu 1713求分数的最小公倍数
  8. Android中SlidingDrawer介绍【安卓进化三十四】
  9. observer 观察者模式
  10. package ‘catkin‘ depends on non-existent package ‘python3-catkin-pkg‘