我有这样的API
@RequestMapping(value = "api/Download", method = RequestMethod.POST)
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String filename = "aman1234.xlsx";
String filepath = "/home/aman/aman1/";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
FileInputStream fileInputStream = new FileInputStream(filepath + filename);
int i;
while ((i = fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();
}
我正在使用此
调用此API<form action="api/Download" method="post">
我第一次使用它时工作正常,网址显示http://localhost:8080/UploadExcel/api/Download
并且一切正常但在重新定向到此页面并发布表单后,网址映射到http://localhost:8080/UploadExcel/api/api/Upload
为什么会这样&# 34; / API&#34;添加到URL。当我删除&#34; / api&#34;从方法和html元素中,一切都完全正常。