?
Solved

jsp with servlets

Posted on 2009-04-29
3
Medium Priority
?
391 Views
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.
0
Comment
Question by:SunScreenCert
3 Comments
 
LVL 5

Assisted Solution

by:TheVeee
TheVeee earned 120 total points
ID: 24262414
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
 
LVL 2

Author Comment

by:SunScreenCert
ID: 24263577
can you please give this code without using logic tags of struts because i am using jsp and servlets
0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 380 total points
ID: 24264041
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

864 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