jsp conditional check

Posted on 2009-04-29
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){%>
Question by:SunScreenCert
    LVL 1

    Assisted Solution

    Remove the call to toString(). If request.getAttribute("billingdetailsuccessmessage") returns null, invoking toString on it will cause a NullPointerException.
    LVL 26

    Accepted Solution

    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

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    It Is not possible to enable LLDP in vSwitch(at least is not supported by VMware), so in this article we will enable this, and also go trough how to enabled CDP and how to get this information in vSwitches and also in vDS.
    OfficeMate Freezes on login or does not load after login credentials are input.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    19 Experts available now in Live!

    Get 1:1 Help Now