I want to use a web form to submit some information and then a JSP page will display the entered form information. However when I clicked the submit button in the form, it goes the correct JSP file but all form values are displayed as "null". I'm using Jersey to do the POST request.
The form is:
<form action="/MyRestWS/rest/customer/created" method="POST">
<table border="1">
<tr>
<td>Customer name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Customer ID:</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>Customer DOB:</td>
<td><input type="text" name="dob"></td>
</tr>
</table>
<br/>
<input type="submit" value="Submit">
</form>
The code to do the requests is:
@Path("/customer")
public class CustomerService {
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("created")
public Response createCustomer(@FormParam("id") int id, @FormParam("name") String name, @FormParam("dob") Date dob) {
Response r;
r = Response.ok().entity(new Viewable("/confirm.jsp")).build();
return r;
}
@GET
@Produces(MediaType.TEXT_HTML)
public Viewable displayForm() {
return new Viewable("/form.html");
}
}
The JSP file displayed is confirm.jsp
and its content is:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Your entered information</title>
</head>
<body>
<h2>
<%
out.println("You've entered the following information:");
%>
</h2>
<p>
Customer Name:
<%=request.getParameter("name")%></p>
<p>
Customer ID:
<%=request.getParameter("id")%></p>
<p>
Customer DOB:
<%=request.getParameter("dob")%></p>
</body>
</html>
If I type the following address in a browser:
http://localhost:8080/MyRestWS/rest/customer
It will show me the form.html
with the form. After I fill out information and click "Submit", it will go to the following address and display the JSP file as specified by the path:
http://localhost:8080/MyRestWS/rest/customer/created
The JSP file shows up correctly but all customer information fields are displayed as "null" like the following:
You've entered the following information:
Customer Name: null
Customer ID: null
Customer DOB: null
So why do I get null values in JSP after submitting the form? What's wrong with my code?