Unexpected Exception caught setting 'x' on class xx:Error setting expression 'xx' with value ['x',]
来源:互联网 发布:字幕视频合成软件 编辑:程序博客网 时间:2024/05/18 16:57
废话不多说,直接进入正题:在用SSH框架敲代码时,遇到这样的一个问题:
Unexpected Exception caught setting 'act' on 'classcn.itcast.shop.adminuser.action.AdminUserAction:
Error setting expression 'act'with value ['signin', ]
其实等跨越两天,解决了这个问题后,回头想想,其实挺简单的,怎么就是不会调试呢!真的是抓狂,网上倒是有解决方案,全英的,看的很费劲的,但还是看啊看啊,最终解决了,,下面我们来一起分析一下这个问题:
我在后台登录窗体的jsp中,form表单中有三个input节点:
<span style="font-size:18px;"><form id="loginForm" action="${pageContext.request.contextPath }/adminUser_login.action" method="post" target="_parent" onsubmit="return validate();"> <table cellspacing="0" cellpadding="0" style="margin-top: 100px" align="center"> <tr> <td><img src="images/login.png" width="178" height="256" border="0" alt="SHOP" /></td> <td style="padding-left: 50px"> <table> <tr> <td>管理员姓名:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>管理员密码:</td> <td><input type="password" name="password" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="进入管理中心" class="button" /></td> </tr> </table> </td> </tr> </table> <input type="hidden" name="act" value="signin" /> </form></span>
然后在点击登录按钮后,提交包含这三个节点的form表单,在action中通过模型驱动接受username和password两个参数,(声明:模型驱动中只有这两个参数)代码如下:
package cn.itcast.shop.adminuser.action;import org.apache.struts2.ServletActionContext;import cn.itcast.shop.adminuser.service.AdminUserService;import cn.itcast.shop.adminuser.vo.AdminUser;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class AdminUserAction extends ActionSupport implements ModelDriven<AdminUser> {//使用模型驱动private AdminUser adminUser = new AdminUser();public AdminUser getModel(){return adminUser;}//注入adminUserServiceprivate AdminUserService adminUserService;public void setAdminUserService(AdminUserService adminUserService) {this.adminUserService = adminUserService;}/** * 后台登录的方法 * */public String login(){//调用service完成登录 AdminUser curAdminUser =adminUserService.login(adminUser); if(curAdminUser == null) { //登录失败 this.addActionError("亲,你的用户名和密码错误!"); return "loginFail"; }else{ //登陆成功 //保存到session中 ServletActionContext.getRequest().getSession().setAttribute("existAdminUser", curAdminUser); return "loginSuccess"; } }}
接着就是报这个错误:(前提:这个错误不影响登录,因为登录只需要两个参数:username和password,)
当然跟着错找到‘act’和‘signin’两个参数,通过这篇文章http://stackoverflow.com/questions/21018018/unexpected-exception-caught-setting-xxx-on-class-xxx-error-setting-expressio,简单知道了原因。
错误原因:在jsp页面中给name为‘act’的节点赋值signin,而当提交form表单后,并没有接收这个参数,所以,这个错的意思就是:给name为‘act’的节点赋值错误。
解决方法:在action中声明该参数act,然后设置get,set方法接收,问题就搞定了。其实根据问题的字面意思就可以看到问题的所在了,分享给出同样问题的童鞋们儿。
- Unexpected Exception caught setting 'x' on class xx:Error setting expression 'xx' with value ['x',]
- Unexpected Exception caught setting 'xx' on 'xxx'
- Unexpected Exception caught setting 'age'-Error setting expression 'age' with value ['3']
- Unexpected Exception caught setting 'upfile' on 'class yuhao.action.FileAction: Error setting expres
- Unexpected Exception caught setting 'username' on 'class cn.lim.action.UserAction: Error setting exp
- Unexpected Exception caught setting 'house.floorage' on 'class action.HouseAction
- Unexpected Exception caught setting
- Unexpected Exception caught setting 'uid' on 'class com.opensymphony.xwork2.ActionSupport: Erro
- Error setting expression '.css' with value
- Error setting expression '0' with value '/'
- struts2 Error setting expression XXXX with value
- Error setting expression 'token' with value...
- Error setting expression 'orderid' with value ['2', ]
- 报错:Unexpected Exception caught setting 'undefined'
- Unexpected Exception caught setting 异常解决记录
- struts2 action 命名冲突导致的Unexpected Exception caught setting 'act' on 'class com.quamnet.backend.cms.ac
- 关于报错WARN OgnlValueStack:49Error setting expression 'pass.x' with value '[Ljava.lang.String;@218c2661
- Error setting expression 'XXX' with value [Ljava.lang.String;@...
- 2015蓝桥杯 曼哈顿距离
- Java架构
- 一般运行时间
- HDOJ1016(搜索DFS)
- Quartz2D - 基本图形绘制(形状)
- Unexpected Exception caught setting 'x' on class xx:Error setting expression 'xx' with value ['x',]
- Hadoop作业提交与停止命令
- Failed to extend swap file from 0 kb to xxx kb.
- java高级---线程、网络、文件、流、序列化等代码示例
- IO流之字符流
- Android常用系统广播
- Multi-digits Recognition Using ConVNet on Mobile categories:
- Dynamic Programming
- UVA10057中位数的定义,个数