<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="wcj.operateData.*,java.util.*,wcj.data.*,wcj.validate.*"%>
<!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=UTF-8">
<title>导出工作记录</title>
</head>
<script language="javascript" type="text/javascript" src="../DatePicker/WdatePicker.js"></script>
<% if(Validator.isAdmin((String)session.getAttribute("name")));
else response.sendRedirect("../index.jsp");
%>
<body>
<form action="<%=request.getContextPath()%>/ExportWorkRecords" method="post">
<div align="center"><img src="../images/logo.gif"></div>
<div align="center"><jsp:include page="navigation.jsp" /></div>
<table width="950" border="1" cellpadding="0" cellspacing="0" bordercolor="#CEE0A5" bgcolor="#FFFFFF" align="center">
<tr align="center">
<td height="30" colspan="8">按条件查询检查记录</td>
</tr>
<tr align="center">
<td width="118" height="30">按姓名查询:</td>
<td width="140"><label>
<select name="name">
<% ArrayList peopleList = (new OperatePeople()).getPeople();
Iterator iter = peopleList.iterator();
while (iter.hasNext()){
%>
<option><%=iter.next()%></option>
<%}%>
<option selected> </option>
</select>
</label></td>
<td width="124">按类别查询:</td>
<td width="142"><label>
<select name="type">
<option>问题管理</option>
<option>工作指令</option>
<option>电子巡检</option>
<option>班组课堂</option>
<option>工艺日检</option>
<option>工艺周检</option>
<option>设备日检</option>
<option>设备周检</option>
<option>安全检查</option>
<option>环保检查</option>
<option>综合检查</option>
<option selected> </option>
</select>
</label></td>
<td width="104">按时间查询:</td>
<td width="140"><label>
<input name="fromDate" type="text" size="15" onClick="WdatePicker({readOnly:true})">
</label></td>
<td width="27">至</td>
<td width="137"><label>
<input name="toDate" type="text" size="15" onClick="WdatePicker({readOnly:true})">
</label></td>
</tr>
<tr align="center">
<td height="30" colspan="8"><label>
<input type="submit" name="Submit" value="导出" onclick="javascript:alert('提交!')">
</label></td>
</tr>
</table>
<jsp:include page="../jsp/foot.jsp"/>
</form>
</body>
</html>
上面那段代码,提交给一个servlet如下:
package wcj.servlet;import java.io.IOException;
//import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import wcj.validate.Validator;
import wcj.operateData.*;
import wcj.util.UtilClass;
import org.apache.poi.hssf.usermodel.*;public class ExportWorkRecords extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
ServletOutputStream output=response.getOutputStream(); try {
String name=request.getParameter("name"),
type=request.getParameter("type"),
fromDate=request.getParameter("fromDate"),
toDate=request.getParameter("toDate"); System.out.println("提交表单确认!");
HSSFWorkbook book=new OperateQuestion().generateWorkRecords(name,type,fromDate,toDate);
book.write(output);
} finally {
output.close(); }
} protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}}
奇怪的问题产生了,当我选择第一个下拉列表框导出的时候,可以正确导出,而且这个jsp页面只调用一次servlet,但是当我选择第二个或者是第三个下拉列表框导出数据的时候,却不能正确导出数据,而是两次调用servlet,但是我只是点击了一次导出按钮,而且,两次调用时,第二次调用servlet的时候传过去的是空值,所以总是报错!请大家帮忙,谢谢了!
<%@page import="wcj.operateData.*,java.util.*,wcj.data.*,wcj.validate.*"%>
<!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=UTF-8">
<title>导出工作记录</title>
</head>
<script language="javascript" type="text/javascript" src="../DatePicker/WdatePicker.js"></script>
<% if(Validator.isAdmin((String)session.getAttribute("name")));
else response.sendRedirect("../index.jsp");
%>
<body>
<form action="<%=request.getContextPath()%>/ExportWorkRecords" method="post">
<div align="center"><img src="../images/logo.gif"></div>
<div align="center"><jsp:include page="navigation.jsp" /></div>
<table width="950" border="1" cellpadding="0" cellspacing="0" bordercolor="#CEE0A5" bgcolor="#FFFFFF" align="center">
<tr align="center">
<td height="30" colspan="8">按条件查询检查记录</td>
</tr>
<tr align="center">
<td width="118" height="30">按姓名查询:</td>
<td width="140"><label>
<select name="name">
<% ArrayList peopleList = (new OperatePeople()).getPeople();
Iterator iter = peopleList.iterator();
while (iter.hasNext()){
%>
<option><%=iter.next()%></option>
<%}%>
<option selected> </option>
</select>
</label></td>
<td width="124">按类别查询:</td>
<td width="142"><label>
<select name="type">
<option>问题管理</option>
<option>工作指令</option>
<option>电子巡检</option>
<option>班组课堂</option>
<option>工艺日检</option>
<option>工艺周检</option>
<option>设备日检</option>
<option>设备周检</option>
<option>安全检查</option>
<option>环保检查</option>
<option>综合检查</option>
<option selected> </option>
</select>
</label></td>
<td width="104">按时间查询:</td>
<td width="140"><label>
<input name="fromDate" type="text" size="15" onClick="WdatePicker({readOnly:true})">
</label></td>
<td width="27">至</td>
<td width="137"><label>
<input name="toDate" type="text" size="15" onClick="WdatePicker({readOnly:true})">
</label></td>
</tr>
<tr align="center">
<td height="30" colspan="8"><label>
<input type="submit" name="Submit" value="导出" onclick="javascript:alert('提交!')">
</label></td>
</tr>
</table>
<jsp:include page="../jsp/foot.jsp"/>
</form>
</body>
</html>
上面那段代码,提交给一个servlet如下:
package wcj.servlet;import java.io.IOException;
//import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import wcj.validate.Validator;
import wcj.operateData.*;
import wcj.util.UtilClass;
import org.apache.poi.hssf.usermodel.*;public class ExportWorkRecords extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
ServletOutputStream output=response.getOutputStream(); try {
String name=request.getParameter("name"),
type=request.getParameter("type"),
fromDate=request.getParameter("fromDate"),
toDate=request.getParameter("toDate"); System.out.println("提交表单确认!");
HSSFWorkbook book=new OperateQuestion().generateWorkRecords(name,type,fromDate,toDate);
book.write(output);
} finally {
output.close(); }
} protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}}
奇怪的问题产生了,当我选择第一个下拉列表框导出的时候,可以正确导出,而且这个jsp页面只调用一次servlet,但是当我选择第二个或者是第三个下拉列表框导出数据的时候,却不能正确导出数据,而是两次调用servlet,但是我只是点击了一次导出按钮,而且,两次调用时,第二次调用servlet的时候传过去的是空值,所以总是报错!请大家帮忙,谢谢了!
<select name="type">
<option>问题管理 </option>
<option>工作指令 </option>
<option>电子巡检 </option>
<option>班组课堂 </option>
<option>工艺日检 </option>
<option>工艺周检 </option>
<option>设备日检 </option>
<option>设备周检 </option>
<option>安全检查 </option>
<option>环保检查 </option>
<option>综合检查 </option>
<option selected> </option>
</select> 你的option怎么没有value
<select name="type">
<option>问题管理 </option>
<option>工作指令 </option>
<option>电子巡检 </option>
<option>班组课堂 </option>
<option>工艺日检 </option>
<option>工艺周检 </option>
<option>设备日检 </option>
<option>设备周检 </option>
<option>安全检查 </option>
<option>环保检查 </option>
<option>综合检查 </option>
<option selected> </option>
</select> 将上面的这段代码改为<select name="type">
<option value="1">问题管理 </option>
<option value="2">工作指令 </option>
<option value="3">电子巡检 </option>
<option value="4">班组课堂 </option>
<option value="5">工艺日检 </option>
<option value="6">工艺周检 </option>
<option value="7">设备日检 </option>
<option value="8">设备周检 </option>
<option value="9">安全检查 </option>
<option value="10">环保检查 </option>
<option value="11">综合检查 </option>
<option selected value="12"> </option>
</select> 可以改过来看下,应该是这儿的问题。
如果还不行,请回复,我在帮你看看!