我无法出口从一个servlet到一个Excel文件的响应。 请参阅下面的代码:
Test.java:
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
out = response.getWriter();
out.print("<form name=\"test\" method=\"post\" action=\"Export\">");
out.print("<table border=\"1\" cellpadding=\"3\" bordercolor='black'");
out.print("<tr>");
out.print("<td>1</td>");
out.print("<td>hello how are you?</td>");
out.print("</tr>");
out.print("</table>");
out.print("<td><input type=\"submit\" name =\"submit1\" value=\"Export To Excel\"></td>");
out.print("</form>");
点击时提交按钮产生excel工作表不包含任何值。 见Export.java
当点击提交按钮时调用。
Export.java
public class Export extends HttpServlet {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String submit1 = request.getParameter("submit1");
if (submit1 != null) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=users.xls");
}
}
}
此外,已经观察到,如果我在写下面的代码Test.java
,其操作正常,并且excel表确实包含表中的值。
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=users.xls");
有没有什么办法的输出转发Export.java
到Test.java
点击提交按钮时。