action接收表单出错Unexpected Exception caught setting 'xxx'on xxx: Error setting expression 

阅读: 评论:0

action接收表单出错Unexpected Exception caught setting 'xxx'on xxx: Error setting expression 'vApp.vehicleT

action接收表单出错Unexpected Exception caught setting 'xxx'on xxx: Error setting expression 'vApp.vehicleT

最近在弄SSH,结果action接收表单传值出现了错误:

三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.deptId' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.deptId' with v
alue '[Ljava.lang.String;@1f7925b4'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.driverId' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.driverId' wi
th value '[Ljava.lang.String;@41800801'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting &#pId' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression &#pId' with val
ue '[Ljava.lang.String;@526440c3'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting &#dTime' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression &#dTime' withvalue '[Ljava.lang.String;@c057566'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.startTime' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.startTime' 
with value '[Ljava.lang.String;@ef5784d'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.vehicleAppType' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.vehicl
eAppType' with value '[Ljava.lang.String;@4f74a992'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.vehicleId' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.vehicleId' 
with value '[Ljava.lang.String;@3f668ae7'
三月 27, 2018 4:21:38 下午 com.opensymphony.xwork2.interceptor.ParametersInterceptor error
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'vApp.vehicleType' on 'class com.caixinhao.vehicleSystem.action.VehicleApplyAction: Error setting expression 'vApp.vehicleTy
pe' with value '[Ljava.lang.String;@186f7628'

首先我们确认struts2action接受表单传值的三种方式:

链接在此

struts2中的Action接收表单传递过来的参数有3种方法:


如,登陆表单login.jsp:

<form action="login" method="post" name="form1">
  用户名:<s:textfield name="username"/><br/>
   密 码:<s:password name="password"/><br/>
               <s:submit value="提交"/> 
   </form>

1.在Action类中定义表单属性,两者属性名称必须一致。提供setter,getter方法。即可接收到表单传过来的参数.

这种接收参数的方法,方便简单,但是结构性不是很好,且当表单传递来的参数很多的时候,整个Action类中充斥着setter,getter方法,程序结构不是很美观。

2.把表单传递过来的参数封装成一个类,然后调用其中的属性.

如,把login.jsp页面要传来的参数进行封装

private String username;
 private String password;
 
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }

然后再Action方法中,定义该类的对象就可以了,如

public class loginAction extends ActionSupport{

private Users users;

public Users getUsers(){

return users;

}

public void setUsers(Users users){

this.users=users;

}

/*

传递过来的参数都封装在users中了,用getter方法取值就可以了

*/

}

通过这种方法传值,还必须在jsp页面做一下处理,login.jsp中from1的属性名应该改成这样:

登陆表单login.jsp:

<form action="login" method="post" name="form1">
  用户名:<s:textfield name="users.username"/><br/>
   密 码:<s:password name="users.password"/><br/>
               <s:submit value="提交"/> 
   </form>

这种方法,在struts开发中是很常用的一种方法!

3.通过实现ModelDriven接口接收表单数据

首先Action类必须实现ModelDriven接口,同样把表单传来的数据封装起来,Action类中必须实例化该对象,并且要重写getModel()方法

public class loginAction extends ActionSupport implements ModelDriven<Users>{

private Users users =new Users();

public Users getModel(){

return users;

}

/*

表单传来的参数封装在users对象中

表单属性名不需要加上引用users对象,直接传参数名

*/

}

我用的是第二种方法,各种代码如下

JSP代码

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<table width="960" border="0" align="center"background="${tPath}/images/bodybg.jpg"><div aligin="left"><s:form action="vehicleApply" >申请车辆出库<s:textfield name=&#pId" label="申请人ID"/><s:textfield name="vApp.driverId" label="驾驶员ID"/><s:textfield name="vApp.vehicleAppType" label="申请类型"/><s:textfield name="vApp.vehicleId" label="车辆ID"/><s:textfield name="vApp.vehicleType" label="车辆类型"/><s:textfield name="vApp.startTime" label="开始时间"/><s:textfield name=&#dTime" label="结束时间"/><s:textfield name="vApp.deptId" label="部门ID"/><tr><td colspan="2"><s:submit value="提交" theme="simple"/><s:reset  theme="simple" value="重填"/></td></tr></s:form></div>
action代码

public class VehicleApplyAction extends EmpBaseAction
{private VehicleApply vApp;public VehicleApply getvApp(){return this.vApp;}public void setvApp(VehicleApply vApp){this.vapp = vApp;}public String execute()throws Exception{// 创建ActionContext实例ActionContext ctx = Context();mgr.addVehicleApply(getvApp());return SUCCESS;}
}

结果还是出错,网上各种百度各种找,后来终于找到了======命名不规范

将vApp命名为vapp,

setvApp命名为setVapp,

马上就不报错了。

命名不规范,结果系统没有检测到setter方法,所有就会出现上面的错误。


本文发布于:2024-01-30 17:34:58,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170660729721692.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:表单   Exception   caught   action   Unexpected
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23