Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Using the HttpSession Object: Servlet and JSP Tutorials J2EE

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
46,081
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Aug 4, 2008

You can see the full screen, high resolution tutorial, here:

http://www.thebookonhibernate.com/j2ee/index.jsp?link=03httpsessionswf

State Management and the HttpSession

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) 6.0 to create a simple Servlet that takes advantage of the HttpSession object of the Servlet and JSP API. The simple Servlet uses a hitcounter to keep track of the number of times the petulant user refreshes the web page.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!

package com.examscam.servlet;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionServlet extends HttpServlet implements Servlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session == null){
session = request.getSession(true);
Integer hitCount = new Integer(0);
session.setAttribute("count", hitCount);
}
Integer hitCount = (Integer)session.getAttribute("count");
hitCount = new Integer(hitCount.intValue() + 1);
session.setAttribute("count", hitCount);
response.getWriter().print("Number of times at this page: " + hitCount.intValue());
}
}

http://www.thebookonhibernate.com/j2e...

Please check out my SCJA Java Certification Mock Exam website:

http://www.scja.com/associate/

And for Hibernate and JPA tutorials, check out: http://www.thebookonhibernate.com

http://www.thebookonhibernate.com/j2ee/index.jsp?link=03httpsessionswf

  • likes, 4 dislikes

Link to this comment:

Share to:

Uploader Comments (javaprogrammingcbts)

  • Um...moderatlye unchristian language, I must say.

    It's the keyboard when I type. Doesn't your keyboard make the same clicking sounds?

Top Comments

  • please remove clak clack sound its irretating

  • Nice tuto...but the typewriter sound sucks !

    Cheers

see all

All Comments (32)

Sign In or Sign Up now to post a comment!
  • What's wrong with your key board at least buy a new keyboard.

  • nice one .. small and precise ...

  • not bad..

  • can session be shared between servlets?

  • What's that I smell?

    It's BULLSHIT from Denver -

    I'd recognise that smug self satisfied

    drivel anywhere - Fuck Off you asshole!

  • please remove the sound clak clak is horrible :s can you usea another sound or anyone

  • Please remove the sound clak clak is horrible can you use another sound or anyone only your voice

  • please remove the sound

  • wer i can download your software? please reply tnx....

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more