我有一个带有锚标记的简单jsp页面,它将调用servlet页面:以下是jsp代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Download Data</title>
</head>
<body>
View data in following format:<br>
<a href = "Filedownload">MS-Excel</a>
</body>
</html>
这是我的servlet页面:
package com.primeki.devlopment.usm.view;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ExcelServlet")
public class Filedownload extends HttpServlet {
private static final long serialVersionUID = 1L;
public Filedownload() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
out.println("Name\tJob\tSalary");
out.println("Raj\tAccountant\t20000");
out.println("Vinay\tAccountant\t20000");
out.println("Rajesh\tAccountant\t20000");
out.println("\tTotal:\t=sum(c2:c3)");
out.close();
}
}
当我单击锚标记时,我得到一个错误...我想制作一个excel表格以通过单击锚标记来下载..但是我遇到了一个错误...请帮助我....
我可能会误会,因为我是Java EE的新手,但<a href = "Filedownload">MS-Excel</a>
锚似乎是Filedownload
在servlet重定向时重定向到的@WebServlet("/ExcelServlet")
。
尝试将锚点更改为<a href = "ExcelServlet">MS-Excel</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句