我正在使用struts 2和tomcat。 我面临的问题是:每当我提交数据是否错误(用户名和密码)时,它都会出现以下字段错误:
.Error setting expression 'userBean.password' with value ['XXX', ]
.Error setting expression 'userBean.username' with value ['YYY', ]
其中'XXX'是密码,'YYY'是用户名。
我的动作类是:
package direstruts.action;
import static com.opensymphony.xwork2.Action.SUCCESS;
import direstruts.model.UserBean;
public class LoginAction extends GenericAction {
@Override
public void validate() {
UserBean uB = getUserBean();
if(uB.getUsername().isEmpty()) {
addFieldError("userBean.username", "Por favor Insira o Username de Utilizador");
}
if(uB.getPassword().isEmpty()) {
addFieldError("userBean.password", "Por favor Insira a Password de Utilizador");
}
}
public String getAuthentication() throws Exception {
if(getUserBean().getAuthentication()) {
addActionMessage("Log in bem Sucedido!");
return SUCCESS;
}
addActionError("Utilizador e/ou Password errados e/ou Utilizador já está logado");
return ERROR;
}
public String setNewUser() throws Exception {
if(getUserBean().setNewUser()) {
addActionMessage("User registado!");
return SUCCESS;
}
addActionError("Utilizador Já Existe! Tente Outro Username!");
return ERROR;
}
public String setQuitUser() throws Exception {
if(getUserBean().setQuitUser()) {
addActionMessage("User LoggedOut!");
return SUCCESS;
}
return ERROR;
}
public UserBean getUserBean() {
if(!session.containsKey("userBean"))
this.setUserBean(new UserBean());
return (UserBean) session.get("userBean");
}
public void setUserBean(UserBean userBean) {
session.put("userBean", userBean);
}
}
我的jsp是:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<title>MeeTO</title>
</head>
<body>
<s:form action="loginAction" method="post" >
<s:label cssClass="login" value="Please fill in the form below in order to Register or Log in:" /> <br>
<s:label for="userBean.username" value="Username:"/>
<s:textfield name="userBean.username" /> <br>
<s:label for="userBean.password" value="Password:"/>
<s:password name="userBean.password" /> <br>
<s:submit value="LogIn" action="loginAction" /> <br>
<s:submit value="Register" action="registerAction" /> <br>
</s:form>
<s:fielderror/>
<s:actionerror/>
<s:actionmessage/>
</body>
</
我的豆是:
package direstruts.model;
import cliente.replies.ReplyLogin;
import cliente.replies.ReplyObj;
import cliente.requests.lookup.GetAuthentication;
import cliente.requests.modify.SetNewUser;
import cliente.requests.modify.SetQuitUser;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;
import servidorRMI.ExecuteCommands;
public class UserBean {
ExecuteCommands eC;
private static String ip_RMI = "127.0.0.1";
private static int serverRMI = 1099;
private static InputStream in;
private String username;
private String password;
private int idUser;
public UserBean() {
readProperties();
}
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;
}
public int getIdUser() {
return this.idUser;
}
public void setIdUser(int idUser) {
this.idUser = idUser;
}
public boolean getAuthentication() {
GetAuthentication gA = new GetAuthentication(getUsername(), getPassword(), 0);
ReplyLogin rL = null;
boolean cond = false;
do{
try {
eC = (ExecuteCommands)Naming.lookup("rmi://" + ip_RMI + ":" + serverRMI + "/ServerRMI");
rL = eC.getAuthentication(gA);
cond = false;
} catch (RemoteException ex) {
System.err.println("Erro no servidor RMI Remote! A tentar restablecer a ligação!");
cond = true;
} catch (NotBoundException ex) {
System.err.println("Erro no servidor RMI NotBound! A tentar restablecer a ligação!");
cond = true;
} catch (MalformedURLException ex) {
System.err.println("Erro no servidor RMI MalformedURL! A tentar restablecer a ligação!");
cond = true;
}
} while(cond);
setIdUser(rL.getIdUser()); // Faz set ao idUser para poder ser usado nos pedidos subsequentes
return rL.isHasRegister();
}
public boolean setNewUser() {
SetNewUser sNU = new SetNewUser(getUsername(), getPassword(), 0);
boolean cond = false;
ReplyObj rO = null;
do{
try {
eC = (ExecuteCommands)Naming.lookup("rmi://" + ip_RMI + ":" + serverRMI + "/ServerRMI");
rO = eC.setNewUser(sNU);
cond = false;
} catch (RemoteException ex) {
System.err.println("Erro no servidor RMI Remote! A tentar restablecer a ligação!");
cond = true;
} catch (NotBoundException ex) {
System.err.println("Erro no servidor RMI NotBound! A tentar restablecer a ligação!");
cond = true;
} catch (MalformedURLException ex) {
System.err.println("Erro no servidor RMI MalformedURL! A tentar restablecer a ligação!");
cond = true;
}
} while(cond);
return rO.getSuccess();
}
public boolean setQuitUser() {
SetQuitUser sQU = new SetQuitUser(idUser, 0);
boolean cond = false;
ReplyObj rO = null;
do{
try {
eC = (ExecuteCommands)Naming.lookup("rmi://" + ip_RMI + ":" + serverRMI + "/ServerRMI");
rO = eC.setQuitUser(sQU);
cond = false;
} catch (RemoteException ex) {
System.err.println("Erro no servidor RMI Remote! A tentar restablecer a ligação!");
cond = true;
} catch (NotBoundException ex) {
System.err.println("Erro no servidor RMI NotBound! A tentar restablecer a ligação!");
cond = true;
} catch (MalformedURLException ex) {
System.err.println("Erro no servidor RMI MalformedURL! A tentar restablecer a ligação!");
cond = true;
}
} while(cond);
return rO.getSuccess();
}
static public void readProperties() {
try {
Properties properties = new Properties();
in = UserBean.class.getClassLoader().getResourceAsStream("app.properties");
properties.load(in);
ip_RMI = properties.getProperty("serverRMI.address");
serverRMI = Integer.parseInt (properties.getProperty("serverRMI.port"));
} catch(IOException e) {
System.err.println("Erro a ler o ficheiro .properties!");
} finally {
if(in != null) {
try {
in.close();
} catch(IOException e) {System.out.println("Erro a fechar!"); }
}
}
}
}
这是Tomcat Log:
19-Nov-2014 14:21:04.618 WARNING [http-apr-8080-exec-109] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.warn Parameter [action:loginAction] is on the excludeParams list of patterns!
19-Nov-2014 14:21:05.086 SEVERE [http-apr-8080-exec-109] null.null Notificação para o Desenvolvedor (altere o paramêtro struts.devMode para false para desabilitar esta mensagem):
Unexpected Exception caught setting 'userBean.password' on 'class direstruts.action.LoginAction: Error setting expression 'userBean.password' with value ['YYY', ]
19-Nov-2014 14:21:05.101 SEVERE [http-apr-8080-exec-109] null.null Notificação para o Desenvolvedor (altere o paramêtro struts.devMode para false para desabilitar esta mensagem):
Unexpected Exception caught setting 'userBean.username' on 'class direstruts.action.LoginAction: Error setting expression 'userBean.username' with value ['XXX', ]
19-Nov-2014 14:21:05.210 WARNING [http-apr-8080-exec-109] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.warn Caught an exception while evaluating expression 'userBean.username' against value stack
Caught an Ognl exception while getting property userBean - Class: ognl.OgnlRuntime
File: OgnlRuntime.java
Method: getMethodValue
Line: 1456 - ognl/OgnlRuntime.java:1456:-1
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:143)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2317)
at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.getValueBody(ASTChain.java:141)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:494)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:255)
at com.opensymphony.xwork2.ognl.OgnlValueStack.getValue(OgnlValueStack.java:358)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValue(OgnlValueStack.java:347)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValueWhenExpressionIsNotNull(OgnlValueStack.java:322)
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:308)
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:366)
at com.opensymphony.xwork2.util.TextParseUtil$1.evaluate(TextParseUtil.java:157)
at com.opensymphony.xwork2.util.OgnlTextParser.evaluate(OgnlTextParser.java:49)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:167)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:112)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:85)
at org.apache.struts2.components.Component.findValue(Component.java:353)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:813)
at org.apache.struts2.components.UIBean.end(UIBean.java:544)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.loginPage_jsp._jspx_meth_s_005ftextfield_005f0(loginPage_jsp.java:273)
at org.apache.jsp.loginPage_jsp._jspx_meth_s_005fform_005f0(loginPage_jsp.java:182)
at org.apache.jsp.loginPage_jsp._jspService(loginPage_jsp.java:114)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2403)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2392)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: ognl.OgnlException: userBean [java.lang.NullPointerException]
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1456)
at ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:60)
at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:147)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.getProperty(ObjectAccessor.java:17)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2317)
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:138)
... 68 more
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at direstruts.model.UserBean.readProperties(UserBean.java:128)
at direstruts.model.UserBean.<init>(UserBean.java:27)
at direstruts.action.LoginAction.getUserBean(LoginAction.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891)
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1454)
... 73 more
19-Nov-2014 14:21:05.288 WARNING [http-apr-8080-exec-109] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.warn NOTE: Previous warning message was issued due to devMode set to true.
19-Nov-2014 14:21:05.429 WARNING [http-apr-8080-exec-109] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.warn Caught an exception while evaluating expression 'userBean.password' against value stack
Caught an Ognl exception while getting property userBean - Class: ognl.OgnlRuntime
File: OgnlRuntime.java
Method: getMethodValue
Line: 1456 - ognl/OgnlRuntime.java:1456:-1
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:143)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2317)
at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.getValueBody(ASTChain.java:141)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:494)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:255)
at com.opensymphony.xwork2.ognl.OgnlValueStack.getValue(OgnlValueStack.java:358)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValue(OgnlValueStack.java:347)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValueWhenExpressionIsNotNull(OgnlValueStack.java:322)
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:308)
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:366)
at com.opensymphony.xwork2.util.TextParseUtil$1.evaluate(TextParseUtil.java:157)
at com.opensymphony.xwork2.util.OgnlTextParser.evaluate(OgnlTextParser.java:49)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:167)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:112)
at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:85)
at org.apache.struts2.components.Component.findValue(Component.java:353)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:813)
at org.apache.struts2.components.UIBean.end(UIBean.java:544)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.loginPage_jsp._jspx_meth_s_005fpassword_005f0(loginPage_jsp.java:313)
at org.apache.jsp.loginPage_jsp._jspx_meth_s_005fform_005f0(loginPage_jsp.java:191)
at org.apache.jsp.loginPage_jsp._jspService(loginPage_jsp.java:114)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2403)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2392)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: ognl.OgnlException: userBean [java.lang.NullPointerException]
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1456)
at ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:60)
at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:147)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.getProperty(ObjectAccessor.java:17)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2317)
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:138)
... 68 more
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at direstruts.model.UserBean.readProperties(UserBean.java:128)
at direstruts.model.UserBean.<init>(UserBean.java:27)
at direstruts.action.LoginAction.getUserBean(LoginAction.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891)
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1454)
... 73 more
19-Nov-2014 14:21:05.507 WARNING [http-apr-8080-exec-109] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.warn NOTE: Previous warning message was issued due to devMode set to true.
[编辑] 我忘了提到我有一个行动,其他所有行动都延伸。 这是:
package direstruts.action;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
public class GenericAction extends ActionSupport implements SessionAware{
protected static final long serialVersionUID = 4L;
protected Map<String, Object> session;
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
}
为了保留动作内存,GenericAction实现了SessionAware。那可以吗?
答案 0 :(得分:1)
如Parameters Interceptor documentation(以及explained in this answer)中所述,例外情况:
.Error设置表达式&#39; userBean.password&#39;有价值[&#39; XXX&#39;,]
意味着你错过了Setter。
JavaBeans约定确定你应该有一个属性,带有一个具有相同名称的getter和setter,Struts2遵循这些原则,通过反射执行内省以概述你的Action对象。
您的代码中有什么内容?
public UserBean getUserBean() {
if(!session.containsKey("userBean"))
this.setUserBean(new UserBean());
return (UserBean) session.get("userBean");
}
public void setUserBean(UserBean userBean) {
session.put("userBean", userBean);
}
有点不合标准,呃!
属性private UserBean userBean;
甚至不存在,getter和setter正在做奇怪的会话事情(虽然他们甚至不应该有任何业务)。
将其更改为
private UserBean userBean;
public UserBean getUserBean() {
return userBean;
}
public void setUserBean(UserBean userBean) {
this.userBean = userBean;
}
它会起作用。
然后如果需要,找到另一种处理会话和对象的方法(例如prepare()
方法,甚至是execute()
)。