struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mathias-ewald <>
Subject Login with Struts2
Date Thu, 16 Jul 2009 18:37:22 GMT


I am trying to implement a login mechanism. I will now explain what I did
and what error I get but in case there is a more sophisticated way to do
that - please tell me!

I created a BaseAction which is the parent of all my Actions. The BaseAction
is supposed to be responsible for displaying a login page if there is no
User object in session scope. Then the login form should put the username
and password into the BaseAction. The BaseAction then tries to find a match
in the database and places the User object into session scope:

public abstract class BaseAction {

	private String username;
	private String password;
	protected Log log;
	private Boolean loginStatus;
	public String execute() {
		if(log == null) {
			log = LogFactory.getLog(getClass());
		if(isProtected()) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			Object o = session.get("user");
			if(o instanceof User) {
				loginStatus = true;
			} else {
				return "login";
		return executeAction();

	public abstract String executeAction();

	public abstract Boolean isProtected();

	public Boolean getLoginStatus() {
		return loginStatus;

	public void setLoginStatus(Boolean loginStatus) {
		this.loginStatus = loginStatus;

	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;

An Action that wants to be password protected must implement #isProtected()
to return "true". This is my JSP file that is shown if #isProtected() ==
true and there's no User in session scope:

	<s:textfield label="Username" name="userData.username"></s:textfield>
	<s:password label="Password" name="userData.password"></s:password>

This is the error I get

20:35:42,179  WARN OgnlValueStack:49 - Error setting value
ognl.OgnlException: target is null for setProperty(null, "password",
	at ognl.OgnlRuntime.setProperty(
	at ognl.ASTProperty.setValueBody(
	at ognl.SimpleNode.evaluateSetValueBody(
	at ognl.SimpleNode.setValue(
	at ognl.ASTChain.setValueBody(
	at ognl.SimpleNode.evaluateSetValueBody(
	at ognl.SimpleNode.setValue(
	at ognl.Ognl.setValue(

Why is that happening?

View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message