jsp with servlets

i have a login,jsp and the servlet check_loginservlet checks whether the user is valid or invalid. In case of invalid login i want it to directed to login.jsp itself but with error message displayed. If i set the error message in session and do session.getAttribute("error") in the jsp it displays null there first time. So what is the way to avoid null display. Do i need to have java code here saying if it is null then do not display anything else display it.
LVL 2
SunScreenCertAsked:
Who is Participating?
 
mrcoffee365Connect With a Mentor Commented:
I'll assume you're not using the built-in login functionality provided with your servlet engine, because this sounds as if you've written your own login.

You should post your code if you want help with it, but I'm going to guess that you have something like this:

<font color="red">Invalid login</font>

What you want is to wrap an if statement around it, like this:

<%
  String errorMsg = (String) session.getAttribute("error");
  if( errorMsg != null && errorMsg.length() < 0 ) {
%>
<font color="red">Invalid login</font>
<%  }  
  session.removeAttribute("error");
%>
0
 
TheVeeeConnect With a Mentor Commented:
Just do a check if present or not in your jsp..

This one is using struts tag lib...

    <logic:present name="name">
        <bean:write name="name" property="name"/>
      </logic:present>
0
 
SunScreenCertAuthor Commented:
can you please give this code without using logic tags of struts because i am using jsp and servlets
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.