웹 양식을 사용하여 정보를 제출하고 JSP 페이지에 입력 된 양식 정보가 표시됩니다. 그러나 양식의 제출 단추를 클릭하면 올바른 JSP 파일로 이동하지만 모든 양식 값은 "null"로 표시됩니다. Jersey를 사용하여 POST 요청을하고 있습니다.JSP에서 null 값을 얻는 이유는 무엇입니까?
양식은 다음과 같습니다
<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>
요청을 수행하는 코드는 다음과 같습니다
는@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");
}
}
표시되는 JSP 파일은 confirm.jsp
이며, 그 내용은 다음과 같습니다
<%@ 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>
나는 경우, 브라우저에 다음 주소를 입력하십시오.
http://localhost:8080/MyRestWS/rest/customer
양식이 표시된 form.html
이 표시됩니다.
http://localhost:8080/MyRestWS/rest/customer/created
JSP 파일이 제대로 표시되지만 모든 고객 정보 필드는 다음과 같이 표시됩니다 : 나는 정보를 입력하고 클릭 한 후에는 다음 주소로 이동 경로에 의해 지정된 JSP 파일을 표시합니다 "제출" 다음과 같은 "null":
You've entered the following information:
Customer Name: null
Customer ID: null
Customer DOB: null
그런데 왜 양식을 제출 한 후 JSP에서 null 값을 얻습니까? 내 코드에 무슨 문제가 있습니까?
** 관련 없음 ** [JSP로 스크립틀릿을 사용하는 것이 좋습니다] (http://stackoverflow.com/a/3180202/814702) – informatik01
@ informatik01 : 귀하의 제안에 감사드립니다. 빠른 프로토 타입을 얻기 위해 JSP를 사용하고 있습니다. – tonga
나는 본다. 내가 경우에 그것을 썼습니다)) – informatik01