It's not a secret anymore!
The moose likes Servlets and the fly likes Servlet Sessions Coding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Sessions Coding" Watch "Servlet Sessions Coding" New topic

Servlet Sessions Coding

Nithish Yalamanchili

Joined: Aug 16, 2007
Posts: 24
Hai All

Iam new to Servlets and JSP's. I need an application that accepts username and password from browser and place the user in session, so that the user can be checked for session. Please anyone provide code for this application.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

At JavaRanch, we don't just provide code.
We prefer to help people learn how to code these things themselves.

What have you got so far?
What part has you confused?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nithish Yalamanchili

Joined: Aug 16, 2007
Posts: 24

I have done upto here. From here where i have to place session object and track the user.

[BPSouther: Added code tags]
[ August 16, 2007: Message edited by: Ben Souther ]
prakash chandra

Joined: Aug 14, 2007
Posts: 24
You have to use Session Tracking in servlets. Session Tracking can be established using any one of the followings:
1. Cookies
2. URL rewriting and
3. Hidden Form Fields

Please go through above topics you will find your answer.

SCJP 6.0
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Create a session and store the username in the session.

You can see the javadoc for HTTPSession , you will find methods to set attribute in session.Check the javadoc for HTTPServletRequest for methods which will create HTTPSession.

Rahul Bhattacharjee
LinkedIn - Blog
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Tip before getting further : we usually use "equals" to compare strings.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Servlet Sessions Coding
It's not a secret anymore!