Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to session in jsp  RSS feed

 
Santosh Tripathi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

here is the code snippet to use session in jsp but it is generating error in session.putValue("s1",str)

code is ------>//

<%@ page language="java" %>
<html>
<%! String str=new String("");
%>
<% HttpSession ses=request.getSession(true);
str-request.getParameter("t1");
ses.putValue("s1",str);//generates error


now t1 is input parameter created using html
 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi santosh,
putValue method has been deprecated, you can try using setAttribute.

Regards,
Kalai Selvan T.
 
Shailesh Chandra
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
str-request.getParameter("t1"); ???

hope this line is typing error.
 
Santosh Tripathi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friend(Kalai)

Thanx for ur quick response.
even setAttribute method is generating error.is it like i have to include any extra package. It is showing null pointer exception

rgs
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh,

Are you trying to pass the session variable to another JSP?

Cheers,
Swamy
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this what you were looking for?



It works fine for me....

Cheers,
Swamy
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"santosh8" -

If you haven't seen my post in your other thread yet, you need to adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake and must constist of a first name and a last name.

You can change your user name here.

Since you stated you are getting a NullPointerException, the only real conclusion is that one of the values on this line is null. It isn't ses, you put the HttpSession into this variable above this line, and if there is a problem with the session you would get an IllegalStateException, not a NullPointerException. The only choice is that the str variable is null. If the line above is actually " str=request.getParameter("t1");[/i] then the reason is that there is no value set for "t1" in the request, and thus null is being assigned to str. According to the JavaDocs for putValue, neither parameter can be null.

Thanks! and welcome to the JavaRanch!
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think "str-request.getParameter("t1");"
Whats that "str-" it shd be replaced by "="

Srini
 
Santosh Tripathi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ramaswamy and All the concerned friend


Thanx ur suggestion worked well and prob is solved.
Have a nice day

regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!