javaweb 前台"文件上传"提交后服务器跳转后发生错误
javaweb 前台"文件上传"提交后服务器跳转后发生错误###### 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; }
###### CONSOLE台输出:
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
###### 如果没有这个forward或是redirect的话, 是可以正常上传的. 从结果看, 就象是用户提交了几次. 想过识别"重复提交"的解决. 想过把req的请求参数清除. 但没弄明白
###### 我想要达到的结果是 未登录时能正常转到登录页面. 而不是得到一个连接重置的结果.