简体   繁体   English

当我尝试使用锚标记从我的jsp页面调用servlet页面时,显示错误

[英]when i am trying to call a servlet page from my jsp page using anchor tag it showing an error

i have a simple jsp page with one anchor tag which will call the servlet page: The following is the jsp code 我有一个带有锚标记的简单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>

This is my servlet page : 这是我的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();
    }

}

I am getting an error when i am clicking the anchor tag ... i want to make an excel sheet to get download by click on the anchor tag .. but i am getting an error ... plz help in this.... 当我单击锚标记时,我得到一个错误...我想制作一个excel表以通过单击锚标记来下载..但是我遇到了一个错误...请帮助我。

I may be mistaken because I am new in Java EE but it seems that <a href = "Filedownload">MS-Excel</a> anchor is redirecting to Filedownload while your servlet is @WebServlet("/ExcelServlet") . 我可能会误会,因为我是Java EE的新手,但是当您的servlet是@WebServlet("/ExcelServlet")<a href = "Filedownload">MS-Excel</a>锚似乎正在重定向到Filedownload
Try changing your anchor to <a href = "ExcelServlet">MS-Excel</a> 尝试将锚定更改为<a href = "ExcelServlet">MS-Excel</a>

您已将WebServlet "/ExcelServlet"命名为WebServlet "/ExcelServlet" ,这意味着它将对对http:// {server} / {app-name} / ExcelServlet的请求进行响应,并且您具有指向href = "Filedownload"的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM