JSP and session : Session « JSP « Java






JSP and session

/*
<%@ page import="com.java2s.*"%>
<html>
<head>
</head>
<body>
<h1>Thankyou for your request</h1>
Thankyou for your request for more information.
It will be sent to you shortly.
<%
  MoreInfoRequest infoRequest = new MoreInfoRequest();
  infoRequest.setCourses(request.getParameter("courses"));
  infoRequest.setFirstName(request.getParameter("firstName"));
  infoRequest.setLastName(request.getParameter("lastName"));
  infoRequest.setEmail(request.getParameter("email"));

  // this is the method that will bind an object to a session
  session.setAttribute("infoRequest", infoRequest);
%>
<p>Click <a href="displayYourRequest.jsp">here</a> to view your request.
</body>
</html>
*/

package com.java2s;

public class MoreInfoRequest
{
  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 getCourses() {
    return courses;
  }
  public void setCourses(String courses) {
    this.courses = courses;
  }

  public String getEmail() {
    return email;
  }
    public void setEmail(String email) {
    this.email = email;
  }

  private String firstName;
  private String lastName;
  private String email;
  private String courses;
}


<body>
<h1>Your Request</h1>
Here is the information that you submitted to us for processing.
<%
  MoreInfoRequest infoRequest =
             (MoreInfoRequest) session.getAttribute("infoRequest");
%>
<br>Course name:<b> <%=infoRequest.getCourses()%></b>
<br>Your name: <b><%=infoRequest.getFirstName()%>
<%=infoRequest.getLastName()%></b>
<br>Your email: <b><%=infoRequest.getEmail()%></b>

</body>
</html>





           
       








Related examples in the same category

1.JSP: display a session info
2.JSP Session Parameter Rewrite
3.JSP New Session Parameter
4.Jsp Session Cart
5.Use Session Jsp
6.Jsp Using Bean Scope Session
7.Print the request headers and the session attributes
8.Using Sessions to Track Users
9.Sessions disabled
10.Duplicated session varaibles
11.JSP: view session
12.JSP and session 2
13.JSP session counter