![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
为什么我struts2使用OGNL表达式老出警告
//User类packagelee;publicclassUser{privateStringname;privateStringpass;publicStringget...
//User类
package lee;
public class User {
private String name;
private String pass;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
//LoginAction
package lee;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private User user;
private String tip;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute()throws Exception{
if(getUser().getName().equalsIgnoreCase("gaojun")&&getUser().getPass().equalsIgnoreCase("123")){
setTip(getUser().getName()+getText("succTip"));
return SUCCESS;
}else{
setTip(getText("failTip"));
return ERROR;
}
}
}
//jsp页面
<body>
<s:form action="login">
<s:textfield name="user.name" key="namelabel"/>
<s:textfield name="user.pass" key="passlabel"></s:textfield>
<s:submit key="Login"></s:submit>
</s:form>
</body>
//提交后控制台输出警告:
2010-12-3 22:46:04 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Error setting expression 'user.name' with value '[Ljava.lang.String;@1a61172'
ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@1a61172)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:198)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:161)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:149)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:276)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:187)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237).... 展开
package lee;
public class User {
private String name;
private String pass;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
//LoginAction
package lee;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private User user;
private String tip;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute()throws Exception{
if(getUser().getName().equalsIgnoreCase("gaojun")&&getUser().getPass().equalsIgnoreCase("123")){
setTip(getUser().getName()+getText("succTip"));
return SUCCESS;
}else{
setTip(getText("failTip"));
return ERROR;
}
}
}
//jsp页面
<body>
<s:form action="login">
<s:textfield name="user.name" key="namelabel"/>
<s:textfield name="user.pass" key="passlabel"></s:textfield>
<s:submit key="Login"></s:submit>
</s:form>
</body>
//提交后控制台输出警告:
2010-12-3 22:46:04 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Error setting expression 'user.name' with value '[Ljava.lang.String;@1a61172'
ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@1a61172)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:198)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:161)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:149)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:276)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:187)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237).... 展开
1个回答
展开全部
首先struts页面中是不是首先要实例化你的user对象,此对象在页面中实例,不然,始终是空的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询