gpt4 book ai didi

java - 当我尝试使用 anchor 标记从 jsp 页面调用 servlet 页面时,它显示错误

转载 作者:行者123 更新时间:2023-12-01 13:47:06 24 4
gpt4 key购买 nike

我有一个简单的 jsp 页面,带有一个 anchor 标记,它将调用 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();
}

}

当我点击 anchor 标记时出现错误...我想制作一个 Excel 工作表,通过单击 anchor 标记来下载..但我收到错误...请帮忙...

最佳答案

我可能弄错了,因为我是 Java EE 的新手,但似乎 <a href = "Filedownload">MS-Excel</a> anchor 正在重定向到 Filedownload而您的 servlet 是 @WebServlet("/ExcelServlet") .
尝试将 anchor 更改为 <a href = "ExcelServlet">MS-Excel</a>

关于java - 当我尝试使用 anchor 标记从 jsp 页面调用 servlet 页面时,它显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20282869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com