Meaningless Drivel is fun!
The moose likes Java in General and the fly likes How to create an HttpSession in a non-servlet class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to create an HttpSession in a non-servlet class" Watch "How to create an HttpSession in a non-servlet class" New topic

How to create an HttpSession in a non-servlet class

Thirumaran Somasundaram

Joined: Oct 29, 2002
Posts: 8
How can we create a HttpSession without a servlet....i mean, an ordinary java class with http do we create this...does any one knows or have a sample coding for it.....please let me know.....
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Thiru,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to comply with the JavaRanch Naming Policy. You can change it here. Thank you for your cooperation.

Why in the world would you want to create a HttpSession object outside a web container? But if you really want to do it, just create a class that implements HttpSession.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Van Glass
Ranch Hand

Joined: Nov 18, 2000
Posts: 110
What are you trying to accomplish? Perhaps with some more information I may be able to point you in the right direction.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

You can use a mock session object. The mock objects website gives you one without having to write any code. It can do almost anything a real session object can do. The mock object is intended to be used for testing.
If your session object is used in real code, you may want to consider changing the interface. It's better to keep the presentation layer separate.
mock objects

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Jeanne, that interests me a lot. Two follow-ups: Your link needs an "s" to become And I couldn't find anything on session there. Maybe it didn't need an "s" and I went the wrong place altogether?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: How to create an HttpSession in a non-servlet class
It's not a secret anymore!