• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and getsession  RSS feed

 
Nathan Vijay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to create session attribute and pass to other JSP pages.



I am having errors when creating session.

Error Message
****************

No method matching getSession() found in interface javax.servlet.http.HttpServletRequest.
HttpSession session = request.getSession();


Following are the lines of code:
CODE
*******


<%@page import="java.sql.*" %>
<%@page import="javax.servlet.*" %>
<%@page import="javax.servlet.http.*" %>

<%
HttpSession session = request.getSession();
String myAttr="";
session.setAttribute("myAttr",shiptoPartySiteId);
%>


Please advise.....
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you don't need to use getSession() in a JSP. JSPs implicitly will provide you with a session object called (appropriately) session.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeroen, how it is possible to get this error. HttpServletRequest has the method getSession. What's wrong with this code?
 
Raja gopal Y
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,
The problem with your code is , the JSP compiler is already have some meaning for the keywork "session", here you are using the keyword as a variable(as you know "WE SHOULD NOT USE KEYWORDS AS VARIABLE NAMES").

Try to use another name like

<%
HttpSession sess = request.getSession();
String myAttr="";
sess.setAttribute("myAttr","test");
%>

It Works..

Hope you are clear what i said.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error should be like, Duplicate names/definition/declaration found or something like that. The error mentioned by original poster is really wiered?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!