jsp with servlets

Posted on 2009-04-29
Last Modified: 2013-11-24
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.
Question by:SunScreenCert
    LVL 5

    Assisted Solution

    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"/>
    LVL 2

    Author Comment

    can you please give this code without using logic tags of struts because i am using jsp and servlets
    LVL 26

    Accepted Solution

    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>
    <%  }  

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now