当我尝试将文件上传到我的服务器时出现问题,出现405 Method POST is not allowed
异常,此异常仅出现在生产中而非本地出现,
这是我的servlet处理表格后请求
public class FileUploadServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
resp.setHeader("Access-Control-Allow-Headers", "*");
resp.setHeader("Access-Control-Allow-Origin", "*");
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
String uploadUrl = blobstoreService.createUploadUrl("/uploadCallback");
uploadUrl = uploadUrl.substring(uploadUrl.indexOf("_") - 1);
req.getRequestDispatcher(uploadUrl).forward(req, resp);
}
}
处理来自' FileUploadServlet'
的请求的servletpublic class FileUploadedCallbackServlet extends HttpServlet {
private static BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
String blobKey = blobs.get(FileUploadInput.FILE_URL).get(0).getKeyString(); // Name of field in form where file name was entered
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print(blobKey);
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
}
}