I can upload file in Java Web Application, but, if I want to send information and upload file, the system upload file and consider the information as null!
My code:
Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("information") == null) System.out.println("information is null"); Helper helper = new Helper(); String url = "C:\\Users\\.....<private url>"; DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(1024); factory.setRepository(new File(url)); ServletFileUpload upload = new ServletFileUpload(factory); try{ List<FileItem> partes = upload.parseRequest(request); for(FileItem items: partes){ File file = new File(url,items.getName()); items.write(file); request.getRequestDispatcher("view/upfile/upfile.jsp").forward(request, response); return; } }catch(Exception e){ request.getSession().setAttribute("error", e.toString() + ": " + url); request.getRequestDispatcher("view/excepciones/message.jsp").forward(request, response); return; }
}
File JSP:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Subir el archivo</h1>
<form action = "<%= request.getContextPath() %>/UpFilesController" method="post" enctype = "multipart/form-data">
<input type = "file" name = "file"/>
<input type = "text" name = "information"/>
<input type = "submit" name = "action4" value = "Subir Archivo"/>
</form>
</body>
Out of GlassFish Server: information is null