what i am doing is, i have designed:
login.jsp:- has the login form.
loginCheck.java:- taking the text field values, and creating object of class authenticate.java and calling the authentication method of authenticate class, and redirecting to the appropriate page based on (login is correct or incorrect).
Authenticate.java:- has the method to authenticate user.
but What i want is when user login with invalid id and password, it should redirect to login.jsp with an error message
if i use only jsp pages, i can do this something like this:
In my login.jsp
In my loginCheck.jsp
but the problem is for checking user authentication, i am not using jsp, but using servlet, so how can i do the same thing in servlet??
If only there a way that a servlet controller could pass information to the JSP. Oh wait! There is!
So, how does a servlet controller pass info to its JSP? (Which, of course, should not contain any Java scriptlets.)
There doesn't need to be any over-complexity to follow best practices:
Easy as pie.
The login forms submits to a task controller that checks the incomgin data and authenticates the user.
If successful, redirects tot he page controller for the main page of the app.
If it fails, records the failure in the session and redirects to the page controller for the login form.
The page controller does whatever prep is necessary, and forwards to the login form.
On the login form page, JSTL and EL (not Java scriptlets) check to see if there's an error recorded on the session and display the error information if present.
The error information is removed from the session as it's already been displayed.
i was also doing in the same way, the only thing was to display the error, but now done.
also i was using scriptlets.