Getting JSP Compile error for session.putAttribute ?

Posted on 2006-05-20
Last Modified: 2012-06-27
In my book.jsp I have,

  String str[]=request.getParameterValues("s1");
<%= session.isNew() %>
<a href="sport.html">sport</a>

Getting "s1" from book.html. But when I try to come to book.jsp from book.html its giving the following error,

C:\DOCUME~1\Gopi\LOCALS~1\Temp\jsp_servlet\ cannot resolve symbol
symbol  : method putAttribute (java.lang.String,java.lang.String[])
location: interface javax.servlet.http.HttpSession
      session.putAttribute("bookpur",str); //[ /book.jsp; Line: 3]
1 error

Question by:gopikrish
    LVL 23

    Accepted Solution

    What about if you change this:


    To this:

    LVL 23

    Expert Comment


    session.getAttribute(); is used to retrive the stored session attributes.

    To set the attributes(Objects) in session you need to use session.setAttribute(); as per basicinstants above suggestion.

    in your case to put the str[] in the session you need to use


    and to retrieve back the stuff

    String arr[] = (String[]) session.getAttribute("bookpur");

    now your stored  session str[] will be got to arr[].

    One more ting make sure you do a null Check when ever you try to retrieve a session Attribute. like

    String arr[] = (String[]) session.getAttribute("bookpur");
    //do some thing.

    Thank You.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
    It can often be challenging to stay relevant in the rapidly evolving world of technology. This can make recruiting talent difficult for companies of all sizes.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    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…

    754 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

    22 Experts available now in Live!

    Get 1:1 Help Now