在跑struts2的时候有时候会出现上面的错,特别是新手,

这种情况是在struts2高级的POJO访问时候出现的s

警告:

Error setting expression 'user.password' with value '[Ljava.lang.String;@1cb2dd1'
ognl.OgnlException: target is null for setProperty(null, "password", [Ljava.lang.String;@1cb2dd1)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)

跟上面差不多的异常,我刚开始也遇到这个比较纠结的问题,下面我来说说我是如何解决的吧,可能大家遇到的跟我的不一样。但是这中间有几个地方需要注意,不然就会出现上面的错。

1、前台jsp

<body>
<form action="<%= path%>/login.action" method="post">
用户名:<input type = "text" name = "user.username"><br/>
密 码:<input type = "text" name = "user.password"><br/>
<input type = "submit" value = "login">
</form>
</body>

注意两个地方,一个是input里面的name要写成**.XX;这里的**就是你后面action中的一个类对象,小写就OK,我这里是一个user,还有就是这里是name=不是id=,如果是用id的话,好像是传不到action中去的。

2、action类

public class Login extends ActionSupport {
public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} private User user = new User(); @Override
public String execute() throws Exception {
System.out.println("username="+user.getUsername()+",password="+user.getPassword());
return SUCCESS;
} }

user类

public class User {
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;
} }

(hibernate+struts)action中的 user类必须得new,如果不new会报空指针

如果是SSH2的话,action中的user不需要new,但是需要注意,在jsp中,user.usernname中的user要和private User user对应。

再一个就是必须得有get/set方法,user的get/set方法。

struts.xml

<package name="login"  extends="struts-default">
<action name="login" class="com.ssh2.action.Login">
<result name="success" type="redirect">/index.jsp</result>
<result name="error" type = "redirect">/login.jsp</result>
</action>
</package>

注意上面几点就没问题了。

关于ognl.OgnlException: target is null for setProperty(null的解决方案的更多相关文章

  1. ognl.OgnlException: target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@1513fd0)

    [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'emaiTypeDto.emailTypeNo' w ...

  2. ognl.OgnlException: target is null for setProperty(null,&quot;XXXX&quot;...)

    今天遇到了这个奇葩问题,最后来回比对了一下前辈写过的一段完整代码后才发现问题. Error大概描写叙述为: 警告: Error setting expression 'XXX' with value ...

  3. com.opensymphony.xwork2.ognl.OgnlValueStack] - target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@6f205e]

    情况1,查询结果未转换为与前台交互的实体类DTO 实体类:EmailTypeDto package com.manage.email.dto; public class EmailTypeDto { ...

  4. 关于target is null for setProperty的问题总结

    出现了这个问题,报错是 com.opensymphony.xwork2.ognl.OgnlValueStack WARN  - Error setting expression 'costRecord ...

  5. root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")

    在执行一个查询语句的时候,mybatis报错:root cause org.apache.ibatis.ognl.OgnlException: source is null for getProper ...

  6. org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "enterpCd")-Mybatis报错

    一.问题由来 下午快要下班时,登录测试服务器查看日志信息,看看有没有新的异常信息,如果有的话好及时修改.结果一看果然有新的异常信息. 主要的异常信息如下: 2020-10-13 14:51:03,03 ...

  7. Android开发中与服务器交互时,遇到java.io.IOException: Target host must not be null的问题

    当我遇到这个问题的时候,也在网上查找好半天.找到了一个和这个问题很类似的问题——java.lang.IllegalStateException: Target host must not be nul ...

  8. source is null for getProperty(null, "cpmodel")异常结局

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderExce ...

  9. IOS开发遇到(null)与<null>轻松处理

    在ios开发中不可避免的我们会遇到服务器返回的值有空值,但是如果是nil也就算了还可能得到(null)以及<null>的返回值,该如何处理呢?(当然有的字典转模型中已处理,可以通过遍历等) ...

随机推荐

  1. Python 线程池的原理和实现及subprocess模块

    最近由于项目需要一个与linux shell交互的多线程程序,需要用python实现,之前从没接触过python,这次匆匆忙忙的使用python,发现python确实语法非常简单,功能非常强大,因为自 ...

  2. Python代码分析工具之dis模块

    转自:http://hi.baidu.com/tinyweb/item/923d012e8146d00872863ec0  ,格式调整过. 代码分析不是一个新的话题,代码分析重要性的判断比较主观,不同 ...

  3. EasyUI 1.4.4 DataGrid(大数据量) bufferview滚动时不加载下一页数据解决方案

    在使用Easyui DataGrid 过程中,发现若单页数据量超过300,IE浏览器加载速度很慢.也通过网上找寻了很多解决方案,最典型的就是去掉datagrid的自动列宽以及自动行高判断. 1.解决自 ...

  4. (转)Newtonsoft.Json序列化和反序列

    这里下载:http://www.newtonsoft.com/products/json/安装:   1.解压下载文件,得到Newtonsoft.Json.dll   2.在项目中添加引用.. 序列化 ...

  5. iOS 9 地图定位崩溃 n: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'

    报错详情: *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/ ...

  6. Fling!

    算法:深搜 很不错的一道题!!! Fling is a kind of puzzle games available on phone. This game is played on a board ...

  7. hadoop文本转换为序列文件

    在以前使用hadoop的时候因为mahout里面很多都要求输入文件时序列文件,所以涉及到把文本文件转换为序列文件或者序列文件转为文本文件(因为当时要分析mahout的源码,所以就要看到它的输入文件是什 ...

  8. jQuery中对未来的元素绑定事件

    对未来的元素绑定事件不能用bind, 1.可以用live代替,但是要注意jquery的版本,根据官方文档,从1.7开始就不推荐live和delegate了,1.9里就去掉live了. 2.推荐用on代 ...

  9. 工作中遇到的浏览器差别(就不叫IE6bug了)

    1.根据ie版本写css <!--[if lt IE 8]> <style> .cntContainer{margin-top: -1px;} </style> & ...

  10. (翻译玩)在使用flask-script的应用上使用gunicorn

    在使用flask-script的应用上使用gunicorn 两周前,我强烈的想要学习一点新知识,像新的语言,新的框架之类的!好让我的大脑忙碌起来,寻找了一些日子后,我决定学习现在越来越流行的云应用平台 ...