Hi all i have couple jsp pages and java class as follows below.Can you help me with the session on the handleForm .jsp As this page supposed to show all info entered by the user in the form.I did manage to display session object in thanks,jsp But have now a problem in doing it in handleForm.jsp.
1User class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package business;
public class User {
public String getName() {
return name;
}
public User()
{}
public User(String name) {
this.name = name;
}
public User(String name, String address, String city, String country, String phone, String email, String gender, String check, String comments) {
this.name = name;
this.address = address;
this.city = city;
this.country = country;
this.phone = phone;
this.email = email;
this.gender = gender;
this.check = check;
this.comments = comments;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCheck() {
return check;
}
public void setCheck(String check) {
this.check = check;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
private String name;
private String address;
private String city;
private String country;
private String phone;
private String email;
private String gender;
private String check;
private String comments;
}
2 index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Please Send Us Your Details</title>
</head>
<body>
<form id="detailsForm" name="detailsForm" method="post" action="thanks.jsp">
<h2>Please Send Us Your Details.</h2>
<table width="730" border="0">
<tr>
<td width="266">Name</td>
<td width="454"><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td height="31">Address</td>
<td><input name="address" type="text" id="address" size="50" /></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="city" id="city" /></td>
</tr>
<tr>
<td>Country</td>
<td><input type="text" name="country" id="country" /></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="phone" id="phone" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Gender</td>
<td><p>
<label>
<input type="radio" name="gender" value="male" id="gender" />
Male</label>
<label>
<input type="radio" name="gender" value="female" id="gender" />
Female</label>
</p></td>
</tr>
<tr>
<td>How Did You Hear About Us?</td>
<td>Twitter<input name="check" type="checkbox" id="check" value="twitter" />
Facebook<input name="check" type="checkbox" id="check" value="facebook" />
Newspaper<input name="check" type="checkbox" id="check" value="newspaper" />
Radio<input name="check" type="checkbox" id="radio" value="radio" />
Other<input name="check" type="checkbox" id="check" value="other" /></td>
</tr>
<tr>
<td>Comments</td>
<td><label for="comments"></label>
<textarea name="comments" id="comments" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td><input type="reset" name="clear" id="clear" value="Clear" /></td>
</tr>
</table>
</form>
</body>
</html>
3 thanks.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" import="business.User"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Passing the input value to a session variable</title>
</head>
<body>
<h1>JSP Process page</h1>
<%
String firstName = request.getParameter("name");
User user = new User(firstName);
session.setAttribute("name", user);
%>
Thank you <%= user.getName() %> for submitting your details !
<br />
Click<a href="handleForm.jsp"> here </a>to view your details again.
</body>
</html>
4 handleForm.jsp
<%@page import="java.util.List"%>
<%@page import="business.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Output page: Fetching the value from session</title>
</head>
<body>
??????????????????????????????????
</body>
</html>