File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes problem in displaying error in jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem in displaying error in jsp page" Watch "problem in displaying error in jsp page" New topic

problem in displaying error in jsp page

Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi ,
I am using servlet and JSP in my application.
Problem is that :-
when a user try to login through login.jsp then this request goes to LoginAction servlet, where DB connection is done .
In this (LoginAction)server if user is not Authentic then it will through an "Invalid Login Attempt By user <userName>".
I want to display this error message on login.jsp.
plz help me in solving this problem.

Thanx in advance..
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
Before redirecting to the JSP from LoginAction Servlet, set the userName in Session and authentication status in reuest as attributes and forward to JSP.

In JSP, You can check if the user is authenticated from the request attribute and display the message accordingly. The userName can alsways be retrieved from the Session.

keep smilin :: sravan<br /><a href="" target="_blank" rel="nofollow">I scribble here</a>
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi Sravan ,
Thanx for your reply.
One thing is that I am already checking user Authentication in servlet then why I have to again check it in jsp.
I want to print(on login.jsp) that mesaage which is thrown by an InvalidLoginException class(in LoginAction servlet).
can I use a concept of errorpage.jsp.
Plz help me with example.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Instead of using an error page, why not forward back to the login jsp?
Before doing so, bind an error message to request scope.
Then, in your JSP, you can display the message.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: problem in displaying error in jsp page
It's not a secret anymore!