Getting JSP Compile error for session.putAttribute ?

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

Who is Participating?
basicinstinctConnect With a Mentor Commented:
What about if you change this:


To this:

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.