JSP Tutorials - Herong's Tutorial Examples
∟JSP Application Session
∟Testing Result of RegForm.jspx
This section describes the testing result of RegForm.jspx, where values are passed from one JSP page to another using different approaches.
Visit the RegForm.jspx JSP page 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 form with
Login Name: Herong
Password: Secret
Favor Color: Red
Click the Submit button, you will get the output of RegDone.jspx page:
Thank you registering 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 to visit 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 on the testing results:
- RegForm.jspx page is designed to serve two functions: presenting the form and
collecting data from the submitted form.
- When RegForm.jspx 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.jspx again and attach all the data in the form
as the query string. This behavior is specified by the <form> tag.
- When RegForm.jspx 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.jspx. Here I use two approaches to pass data to RegDone.jspx.
- "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.
Table of Contents
About This Book
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
JSP Scripting Elements
Java Servlet Introduction
JSP Implicit Objects
Syntax of JSP Pages and JSP Documents
►JSP Application Session
What Is a Session
The "session" Implicit Object
Passing Values between JSP Pages
►Testing Result of RegForm.jspx
Using Perl LWP Package for Debugging
Managing Cookies in JSP Pages
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Performance of JSP Pages
EL (Expression Language)
Overview of JSTL (JSP Standard Tag Libraries)
JSTL Core Library
JSP Custom Tags
JSP Java Tag Interface
Custom Tag Attributes
Multiple Tags Working Together
File Upload Test Application
Using Tomcat on CentOS Systems
Using Tomcat on macOS Systems
Connecting to SQL Server from Servlet
Developing Web Applications with Servlet
Archived Tutorials
References
Full Version in PDF/EPUB