I'm using struts 2 and tomcat together. The problem I'm facing is: whenever I submit data whether is wrong or not (username and password) it ALLWAYS makes following field error appear:
.Error setting expression 'userBean.password' with value ['XXX', ]
.Error setting expression 'userBean.username' with value ['YYY', ]
where 'XXX' is the password and 'YYY' is the username.
My action class is:
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);
}
}
My jsp is:
<%@ 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>
</
My bean is:
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!"); }
}
}
}
}
Here is 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.
[EDIT] I forgot to mention I have an action in which all other actions extend. Here it is:
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;
}
}
To preserve action memory, the GenericAction implements SessionAware. Is that ok?
As reported in Parameters Interceptor documentation (and also explained in this answer), the exception:
means you are missin a Setter.
JavaBeans convention establishes that you should have a property, with a getter and a setter with the same name, and Struts2 works following those principles, performing introspection through reflection to outline your Action's objects.
What do you have in your code instead ?
A little un-standard, uh !
The property
private UserBean userBean;
does not even exists, and getters and setters are doing strange session things (while they should not even have any business).Change it to
And it will work.
Then IF needed, find another way to deal with the session and your object (like
prepare()
method, or evenexecute()
).