Class 2 | Intermediate Java 30-IT-397 |
Sessions
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form name = "userinfo" method = "GET" action = "sessionsexample.jsp">
Name: <input type = "text" name = "name">
Year: <input type = "text" name = "year">
Degree: <INPUT type = "text" name = "degree">
<input type = submit>
</form>
</BODY>
</HTML>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class"
/> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName"
/> --%>
<%
// populate a bean, add it to the session.
Student student = new Student();
student.setName(request.getParameter("name"));
student.setYear(request.getParameter("year"));
student.setDegree(request.getParameter("degree"));
// Place our student in the session.
session.putValue("student", student);
%>
Congratulations <%= student.getName() %>, your registration is
complete!
<br>
<a href = "sessionresults.jsp">Continue</a>
</body>
</html>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class"
/> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName"
/> --%>
<%
// get user info out of the session
Student student = (Student) session.getValue("student");
// Print out the data. Note the mix of Java and HTML.
if (student != null) { %>
Your data:<BR>
Name: <%= student.getName() %> <BR>
Year: <%= student.getYear() %> <BR>
Degree: <%= student.getDegree() %> <BR>
<% } else { %>
There was a problem retrieving your data.
Sorry, you're just plain out of luck.
<% } %>
</body>
</html>
/*
* Student.java
*
* Created on May 21, 2002, 11:43 PM
*/
/**
*
* @author default
*/
public class Student {
/** Holds value of property year. */
private String year;
/** Holds value of property degree. */
private String degree;
/** Holds value of property name. */
private String name;
/** Creates a new instance of Student */
public Student() {
}
/** Getter for property year.
* @return Value of property year.
*/
public String getYear() {
return this.year;
}
/** Setter for property year.
* @param year New value of property year.
*/
public void setYear(String year) {
this.year = year;
}
/** Getter for property degree.
* @return Value of property degree.
*/
public String getDegree() {
return this.degree;
}
/** Setter for property degree.
* @param degree New value of property
degree.
*/
public void setDegree(String degree) {
this.degree = degree;
}
/** Getter for property name.
* @return Value of property name.
*/
public String getName() {
return this.name;
}
/** Setter for property name.
* @param name New value of property name.
*/
public void setName(String name) {
this.name = name;
}
}
Created by: Brandan Jones December 17, 2001