Iam developing a login module
Home page has action named WelcomeAction.java
On Login, request i.e username & password submitted to LoginAction.java
When a user enters incorrect username & password,
i send him/her back to the Home page.
Well i detect that user is invalid in LoginAction.java .Here i add a message 'loginNosuchuser' in the request scope & and move to WelcomeAction.java
Here i check if in request scope message 'loginNosuchuser' is present.If present i make an html:errors object containing 'error.login.Nosuchuser' and call saverrors() and move to the main.jsp
In the main.jsp using html:errors tag i display the error which says "Incorrect Username and/or Password.".This message is picked up from MessageResources.properties file
The message gets Displayed--Incorrect Username and OR Password specified
PROBLEM:
--------
Same way if a logged in user again tries to log in ,log in is denied and the same logic is followed. i.e
When i detect that user is already logged in then i add a message 'userAlreadyLogged' in the request scope in LoginAction.java
and move to WelcomeAction.java.Here i check if in request scope message 'userAlreadyLogged' is present.If present i make an html:errors containing 'error.login.sessionpresent' object and call saveerrors() and move to the main.jsp
In the main.jsp using html:errors tag i want to display the error which says "This User currently logged in elsewhere.".
This message is picked up from MessageResources.properties file
>>>But this message DOESNOT GET DISPLAYED on the
jsp file named main.jsp
My Source code follows
-------WelcomeAction.java----------
Loginproblem = (
String) request.getAttribute("userSessionRunning");
if (Loginproblem != null && Loginproblem.equals("userloggedin"))
{
logger.info("User session currently running" + Loginproblem);
errors.clear();
errors.add("loginNosuchuser",new ActionError("error.login.Nosuchuser"));
//errors.add("sessionpresent",new ActionError("error.login.sessionpresent"));
saveErrors(request,errors);
}
Loginproblem = (String) request.getAttribute("loginNosuchuser");
if (Loginproblem != null && Loginproblem.equals("nosuchuser"))
{
logger.info("loginNosuchuser " + Loginproblem);
//No such user
errors.clear();
errors.add("loginNosuchuser",new ActionError("error.login.Nosuchuser"));
saveErrors(request,errors);
}
--------------LoginAction.java----------------
IntranetLogin intrauserlogin = new IntranetLogin();
intrauserlogin = loginManager.checkIntranetuser(uname,pwd);
//if null is returned then it means wrong username&password
if(intrauserlogin == null)
{
//No such user
logger.fatal("loginfailed reason: User not existing");
request.setAttribute("loginNosuchuser","nosuchuser");
return mapping.findForward(Constants.FAILURE_KEY);
}
else
{
//code to check if the user is currently logged in & to show proper message
if (intrauserlogin.getCurrentlyloggedinFlag().equalsIgnoreCase("T"))
{
//the user is currently logged in
logger.fatal("User trying to relogin having 1 session already running");
request.setAttribute("userSessionRunning","userloggedin");
return mapping.findForward(Constants.FAILURE_KEY);
}
else
{
//code to set username is request scope so that it can be displayed in Title bar of the Browser request.setAttribute("usernaam",intrauserlogin.getFullname());
return mapping.findForward(Constants.SUCCESS_KEY);
}
---------------main.jsp-----------------------
NOTE: used plus instead of html greater than and less than symbol
+logic
resent name="loginNosuchuser"
+html:errors property="loginNosuchuser"/+
+/logic
resent
+logic
resent name="sessionpresent"
+html:errors property="sessionpresent"/+
+/logic
resent
--------MessagesResources.properties---------------
error.login.Nosuchuser=Incorrect Username and/or Password.
error.login.sessionpresent=This User currently logged in elsewhere.
Why is the second errors message named 'sessionpresent' not displayed while the first one 'loginNoSuchUser' gets displayed
IS IT THAT WE CANNOT USE MORE THAN 1 html:errors ???
thanks