Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

JSP: View Session

The view consists of the Html page or the jsp components that provide the user interface. View is what we see. It is mainly for presentation.

JSP: View Session

                          

The view consists of the Html page or the jsp components that provide the user interface. View is what we see. It is mainly for presentation.

Java Bean: - It is a reusable component. It contains the setter and getter methods to set and get the values from the jsp page or database.

In session whenever a request comes for any resource, a unique token is generated by the server and transmitted to the client by the response object and stored on the client machine as a cookie. We can also say that the process of managing the state of a web based client is through the use of session IDs. Session IDs are used to uniquely identify a client browser, while the server side processes are used to associate the session ID with a level of access. Thus, once a client has successfully authenticated to the web applicatiion, the session ID can be used as a stored authentication voucher so that the client does not have to retype their login information with each page request.

In this program we are using the java Beans to set the values from the html page and set it to the jsp page which will works like a controller.
setAttribute(): is used to set the object. A key is set to look up the object. 
getAttribute(): is used to get the object.

The code of the program is given below:

<html>
	<head>
		<title>View and Session</title>
	</head>
	<body>
		<form method = "get" action = "JspAndSessionJsp.jsp">
		Enter your first Name : <input type = "text" name = "firstName"><br>
		Enter your last Name  : <input type = "text" name = "lastName"><br>
		Enter your email      : <input type = "text" name = "email"><br>
		Enter the address      : <input type = "text" name = "address"><br>
		<input type = "submit" name = "submit" value ="submit"><br>
		</form>
	</body>
</html>

 

package Mybean;
public class JspAndSession{
	private String firstName;
	private String lastName;
	private String email;
	private String address;
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getEmail() {
		return email;
	}
    public void setEmail(String email) {
		this.email = email;
	}
}

 

<%@ page import = "Mybean.JspAndSession"%>
<html>
	<body>
		<h1>Your Request</h1>
		Here is the information that you submitted to us for processing.<br>
		<%
		  JspAndSession jas = new JspAndSession();
             jas.setFirstName(request.getParameter("firstName"));
			 jas.setLastName(request.getParameter("lastName"));
			 jas.setEmail(request.getParameter("email"));
			 jas.setAddress(request.getParameter("address"));
		%>
		<% session.setAttribute("jas",jas ); %>
		<a href = "JspSessionView.jsp">Click Here to go forward</a>
	</body>
</html>

The output of the program is given below:

Download this example.


 

                          

» View all related tutorials
Related Tags: html c com jsp ide interface io view components user page vi component int id nsis ai js for ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

please give names to that code for under standing of which code is which name.

Posted by rajesh on Tuesday, 01.29.08 @ 15:45pm | #46490

it seems som jsp is missing to show session values in the last jsp

Posted by rahul on Wednesday, 06.6.07 @ 23:52pm | #18436

 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.