wood burning stoves 2.0*
The moose likes Struts and the fly likes Login - revisited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Login - revisited" Watch "Login - revisited" New topic
Author

Login - revisited

David Pizon
Greenhorn

Joined: Oct 03, 2004
Posts: 10
I am a Struts newbie attempting to write a login app.

Most (if not all) of the examples I have found online use three JSP pages:

login.jsp (prompts user for username/password, re-displays if invalid)
fail.jsp (username/password valid but incorrect)
success.jsp (username/password was correct)



I would like to change my app to have use only two JSP pages:

login.jsp (prompts user for username/password, re-displays if invalid, re-displays if incorrect)
success.jsp (username/password was correct)

I have an Action which validates user input and, if valid, invokes a bean to authenticate the user.

I presume I need three findForwards in my Action:
return (mapping.findForward(this.FORWARD_invalid));
return (mapping.findForward(this.FORWARD_incorrect));
return (mapping.findForward(this.FORWARD_success));

How do I let the login.jsp page know which error condition to display ("invalid field", "could not authenticate", or no error)?

Am I on the right track?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

If user fails authentication, add an ActionError/ActionMessage from the Action and then forward the user to the input forward.

Then in your login.jsp make sure to have the html:errors/messages tag to display the error.


A good workman is known by his tools.
David Pizon
Greenhorn

Joined: Oct 03, 2004
Posts: 10
"add an ActionError/ActionMessage from the Action"

Right... how do I do that?

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;

I want to keep authentication in the LoginAction separate from validation in the LoginForm. Can I stuff an ActionErrors() object in an ActionForward() object?
 
Don't get me started about those stupid light bulbs.
 
subject: Login - revisited
 
Similar Threads
Which is Model and Controller in this example?
Invalid user error message
Trouble with attributes and redirect
Using Struts and AJAX together causing redirection problems.
how to display errors in servlet