2つ以上の行の列を更新してサーブレットに取得しようとした後、値を取得しようとすると、サーブレットで1つの値しか取得できず、2つ以上の行を送信する必要があります。そうしないと、プロジェクトの更新されたリストを別のサーブレットに送信できます私はやろうとしています私は彼女に書いていますplzはサーブレットとJSPで新しい私を助けてくれます
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="com.nousinfo.tutorial.employee.service.model.bo.EmployeeProjectBO"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@page import="com.nousinfo.tutorial.employee.service.model.bo.EmployeeBO"%>
<!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>Update Project</title>
<link rel="stylesheet" href="css/style.css" type="text/css"></link>
</head>
<body >
<form action="ProjectUpdateServlet">
<table border="1" width="500" id="tbl">
<tr>
<td width="234"><b>click</b></td>
<td width="119"><b>Employee Number</b></td>
<td width="234"><b>Project Code</b></td>
<td width="234"><b>Start Date</b></td>
<td width="234"><b>End Date</b></td>
<td width="234"><b>Role</b></td>
</tr>
<c:forEach var="employeeProjectBO" items="${sessionScope.projectList}">
<tr>
<td><input type="checkbox" value='${employeeProjectBO.projectCode}' name="projectCode"></td>
<td><input type="text" value='${employeeProjectBO.employeeNumber}' name="employeeNumber" readonly="readonly"/></td>
<td><input type="text" value='${employeeProjectBO.projectCode}' name="projectCode" readonly="readonly"/></td>
<td><input type="text" value='${employeeProjectBO.startDate}'name="startDate"/></td>
<td><input type="text" value='${employeeProjectBO.endDate}' name="endDate"/></td>
<td><input type="text" value='${employeeProjectBO.role}' name="role"/></td>
<td><input type="hidden" name="updateStatusProject" value="M" /></td>
</tr>
</c:forEach>
</table>
<p> </p>
<br />
<table width="200" border="0" align="center">
<tr>
<td><center>
<input type="submit" name="submit" value="update" onclick="self.close()">
</center></td>
<td><center>
<input type="button" name="cancle" value="cancle"
onclick="self.close()"/>
</center></td>
</tr>
</table>
<hr size="1" width="786">
<p> </p>
</form>
</body>
</html>
これが私のサーブレットです
package com.nousinfo.tutorial;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.nousinfo.tutorial.employee.service.model.bo.EmployeeProjectBO;
/**
* Servlet implementation class ProjectUpdateServlet
*/
public class ProjectUpdateServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ProjectUpdateServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String[] projectCode= request.getParameterValues("checkedProject");
for(int i=0; i<projectCode.length; i++) {
System.out.println(projectCode[i]);}
System.out.println(request.getSession().getAttribute("projectList"));
if (request.getParameter("submit") != null) {
request.getSession().setAttribute("employeeProjectBO",
setEmployeeProject(request));
}
}
public EmployeeProjectBO setEmployeeProject(HttpServletRequest request) {
EmployeeProjectBO employeeProjectBO = new EmployeeProjectBO();
String[] projectCode= request.getParameterValues("checkedProject");
for(int i=0; i<projectCode.length; i++) {
employeeProjectBO.setUpdateStatus(request.getParameter("updateStatusProject").charAt(0));
employeeProjectBO.setEmployeeNumber(Long.parseLong(request
.getParameter("employeeNumber")));
employeeProjectBO.setProjectCode(request.getParameter("projectCode"));
employeeProjectBO.setStartDate(new java.sql.Date(getDate(
request.getParameter("startDate")).getTime()));
employeeProjectBO.setEndDate(new java.sql.Date(getDate(
request.getParameter("endDate")).getTime()));
employeeProjectBO.setRole(request.getParameter("role"));
System.out.println(request.getParameter("role"));}
return employeeProjectBO;
}
private static Date getDate(String source) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
return format.parse(source);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return new Date();
}
}
}