struts2中 No result defined for action

No result defined for action itcast.struts.kkgs.demo2.UserAction1 and result input

1.核对struts.xml中的 class 位置 crtl 鼠标左击 ,看看能不能跳转到目的页面
2.有可能struts2中自动收集表当参数的时候,未找到对应的class能收集该表单参数的

demo1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>struts2的数据封装</h1>
	<form action="${pageContext.request.contextPath}/userAction1" method="post">
		用户名:<input type="text" name="username" /><br/>
		密码:<input type="password" name="password" /><br/>
		年龄:<input type="text" name="age" /><br/>
		生日:<input type="text" name="birthday" /><br/>
		工资:<input type="text" name="salary" /><br/>
		<input type="submit" value="提交" /><br/>
	</form>
<h3></h3>
</body>
</html>

UserAction1

package itcast.struts.kkgs.demo2;

import java.sql.Date;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 数据封装方式一:提供属性的set方法的方式
 * 
 * @author KKGS
 *
 */

public class UserAction1 extends ActionSupport{

	//提供了对应的属性
	private String username;
	private String password;
	private Date birthday;
	private Integer age;
	private Double salary;
	
	
	@Override
	public String execute() throws Exception {
		System.out.println("进入useraction。。。");
 		//接收数据
		System.out.println(username);
		System.out.println(password);
		System.out.println(age);
		System.out.println(salary);
		
		return NONE;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public void setAge(Integer age) {
		this.age = age;
	}


	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}


	public void setSalary(Double salary) {
		this.salary = salary;
	}

}

当表单中age 输入英文字母的话 UserAction中设置了接收参数 age为Integer类型,参数不匹配,会向struts2中的错误信息区 存放类型转换错误,当该请求执行完毕后,struts会检查错误信息区是否有信息,如果有会转到INPUT视图就提示上述错误。
可以在struts.xml中配置input 转向视图
<result name="input">/demo2/demo1.jsp </result>
jsp页面回显错误信息
<s:fielderror />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值