JSP and JSTL Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 3.09, 2006

JSP Sessions and Debugging

Part:   1  2  3  4 

JSP/JSTL Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Using Cookies

Using JavaBean Classes

HTTP Response Header Lines

Non ASCII Characters

JSTL and Expression Language

File Upload

Execution Context

JSP Elements

JSP Standard Tag Libraries (JSTL)

JSP Custom Tag

... Table of Contents

(Continued from previous part...)

Request RegForm.jsp with a browser, you will get a page similar to this:

Registration Form:

Login Name:
Password:
Favor Color:

Your session ID is 2B20E475CA7B0FFC4C2E752ABF24C772
Last user on the server: Nobody

Then fill in the page with

Login Name: Herong
Password: Secret
Favor Color: Red

Click the Submit button, you will get the output of RegDone.jsp page:

Thank you registrating with us:
Login Name: Herong
Password: Secret
Favor Color: Red
Your session ID is 2B20E475CA7B0FFC4C2E752ABF24C772
Last user on the server: Herong

Then close your browser, and start it again with RegForm.jsp, you will get:

Registration Form:

Login Name:
Password:
Favor Color:

Your session ID is A497631211582DE3799223EEF31BCF4F
Last user on the server: Herong

A number of interesting notes:

  • RegForm.jsp page is designed to serve two functions: presenting the form and collecting data from the submitted form.
  • When RegForm.jsp is requested for the first time, there will be no "submit" in the query string. So the JSP code will continue with the presenting-form section.
  • When the user finishes filling in the form, and clicks the Submit button, the browser will request RegForm.jsp again and attach all the data in the form as the query string. This behavior is specified by the <form> tag.
  • When RegForm.jsp is requested by the Submit button, "submit" will have "Submit" as its value. So the JSP code will continue with the collecting-data section.
  • In the collecting-data section, I want to pass the collected data to another JSP page, RegDone.jsp. Here I use two approaches to pass data to RegDone.jsp.
  • "name" and "pass" are passed through the session object. This is probably the best approach to pass data from one JSP page to another.
  • "color" is passed as part of the redirect URL. It will show up in the browser's URL area. So you should not use this approach to pass sensitive information from one JSP page to another.
  • The application object is also used to pass "name" from RegForm.jsp to RegDone.jsp. This copy of "name" is used as the "last user on the server", which is not session specific. In general, passing session specific data through the application object is not safe. Different sessions could override each other.
  • When the browser is closed and started again, a new session object is created but the application is still the same. This is why you see "Herong" again as the last user on the server.

HTTP Communication Level Debugging

If you have a problem with your JSP application at the HTTP communication level, one good debugging tool is the Perl LWP package. It can be used as a Web browser to talk to your JSP application, and to log everything at the HTTP communication level.

(Continued on next part...)

Part:   1  2  3  4 

Dr. Herong Yang, updated in 2006
JSP and JSTL Tutorials - Herong's Tutorial Notes - JSP Sessions and Debugging