文件上传后服务器跳转发生错误
javaweb 中, html页面input type=file 直接点出"上传"或选择一个小文件再点出"上传"时, 会因为没登录而成功转到别的页面. 选中一个2M以上的文件点上传, 服务器如果转发或是发送redriect时, 都会执行多次, 比如 ,下图展示的结果, filter拦截到2到3次. 前台浏览器等待一段时间后, 得到的结果是 ERR_CONNECTION_RESET
HTML页面:
<form action="<%=request.getContextPath() %>/s/FileUpload.yc" method="post" enctype="multipart/form-data">
请选择一个文件: <input type="file" name="upload" > <br><br>
<input type="submit" value="上传"/>
</form>
SERVLET
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//req.setCharacterEncoding("UTF-8");
System.out.println("uploadservlet doGet excecuting...");
if(req.getSession().getAttribute("login") != null && (boolean)req.getSession().getAttribute("login")) {//登录
;
}else {//没登录
System.out.println("uploadservlet doGet forward showinfo.jsp...");
req.setAttribute("result", "没登录不能上传文件!!!");
req.setAttribute("forward", "/login.jsp");
req.getServletContext().getRequestDispatcher("/showinfo.jsp").forward(req, resp);return;
}
Filter ServletCharacterEncoding: /ftpWeb/s/FileUpload.yc uploadservlet doGet excecuting uploadservlet doGet forward showinfo.jsp Filter ServletCharacterEncoding: /ftpWeb/s/FileUpload.yc uploadservlet doGet excecuting uploadservlet doGet forward showinfo.jsp Filter ServletCharacterEncoding: /ftpWeb/s/FileUpload.yc uploadservlet doGet excecuting uploadservlet doGet forward showinfo.jsp
建议使用springboot
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。