aspose file tools
The moose likes Servlets and the fly likes Regarding HttpSession Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Regarding HttpSession " Watch "Regarding HttpSession " New topic
Author

Regarding HttpSession

Swapna latha
Ranch Hand

Joined: Dec 18, 2011
Posts: 54
Hi all !
I got confused with set and get attributes in HttpSession interface. Please see the below attached program:

Here its working fine but if i change date to date1 in getAttribute its showing error but if i write as
Date date=new Date(); then if i change date to date1 in getAttribute its not showing error . Why so ?

Thanks & Regards
Kori Swapna Latha.
Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Hi Latha,

Before you post the java code , use code tag. Because it is used to easy view your code.


Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Do you mean if you change line 34 from date = new Date(); to Date date = new Date();? You're then trying to declare a new variable with the same name as an existing variable (the one you declare on line 29).


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Swapna latha
Ranch Hand

Joined: Dec 18, 2011
Posts: 54


if i write


this type of code its accepting but if i put



its giving an error why So ?
Vijayamoorthi Periasamy
Greenhorn

Joined: Feb 13, 2008
Posts: 3

Date date1=(Date)hs.getAttribute("date");
if(date1!=null)\{
.........
}
date=new Date();
..............
................

its giving an error why So ?


You have created the date1 variable and assigning the session date object to it.

But in the next line you are creating a new date object and assiging to the "date" variable but the variable is not even created.
Try Date date = new Date();
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Regarding HttpSession
 
Similar Threads
Correct way to use getSession() in actions?
request.getSession() vs request.getSession(boolean create)
request.getSession(false)
Session related Question
how to create a session