Java 当我试图使用锚定标记从jsp页面调用servlet页面时,它显示了一个错误
我有一个简单的jsp页面,带有一个锚定标记,它将调用servlet页面: 下面是jsp代码Java 当我试图使用锚定标记从jsp页面调用servlet页面时,它显示了一个错误,java,jsp,servlets,Java,Jsp,Servlets,我有一个简单的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
<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>
我在单击锚定标记时出错。。。
我想制作一张excel表格,通过点击锚定标签下载。。但是我得到了一个错误。。。plz在这方面的帮助…我可能错了,因为我是Java EE新手,但当您的servlet是
@WebServlet(“/ExcelServlet”)
时,锚点似乎正在重定向到文件下载
尝试将您的锚更改为
您已将您的WebServlet”/ExcelServlet“
,这意味着它将响应对http://{server}/{app name}/ExcelServlet的请求,并且您有一个与href=“Filedownload”
的链接。。。怎么了?
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();
}
}