?
Solved

jsp conditional check

Posted on 2009-04-29
2
Medium Priority
?
1,781 Views
Last Modified: 2012-05-06
i have this code but it throws error. Please tell me where i am wrong
<%if(((request.getAttribute("billingdetailsuccessmessage")).toString()) != null){%>
                        <%=request.getAttribute("billingdetailsuccessmessage")%>
                        }%>
0
Comment
Question by:SunScreenCert
2 Comments
 
LVL 1

Assisted Solution

by:jan42
jan42 earned 80 total points
ID: 24264008
Remove the call to toString(). If request.getAttribute("billingdetailsuccessmessage") returns null, invoking toString on it will cause a NullPointerException.
0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 120 total points
ID: 24264072
You have other questions related to session.getAttribute().

jan42 is right that you can get NullPointerExceptions if the returned value is null.

The right way to handle it is
String bdsMessage = (String) request.getAttribute("billingdetailsuccessmessage");

if( bdsMessage != null ) {
  // your code here
}
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Google webmaster tool or Google search console is an imperative tool for solving different website relevant issues. The amazing features of this tool greatly help to check the indexing and improve the visibility of the site.
Welcome back to our beginners guide of the popular Unix tool, cron. If you missed part one where we introduced this tool, the link is below. We left off learning how to build a simple script to schedule automatic back ups. Now, we’ll learn how to se…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

609 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