Ich kann Datei in Java-Webanwendung hochladen, aber, wenn ich Informationen senden und Datei hochladen möchte, das System Datei hochladen und betrachten die Informationen als null !Wie eine Datei hochladen und Text-Ebene Informationen in Java-Webanwendung mit POST senden
Mein Code:
Servlets:
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; }
}
Datei 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>
Von Glassfish Server: Informationen ist null
Diese Frage wurde bereits beantwortet hier: http://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet –