java - Can't get parameters via POST request -


Want to scale a module of uploading files to the server, skeleton of this project. In addition to photos, they want to make thumbnails. The size of the thumbnail is selected on the jsp page and the servlet is sent to it. The problem is that I can not get those parameters through the request.getParameter ("name") pointpoint = "upload" method = "post" enctype = "multipart / form-data "& Gt; & Lt; Input type = "file" name = "file" multiple id = "file" onchange = "check ('file')" /> & Lt; Br> & Lt; Div id = "set_stumbnail" style = "display: none;" & Gt; & Lt; Input type = "checkbox" name = "thumbnail" id = "thumbnail" onclick = "set visable ('thumbnail', 'shape template input')" /> & Lt; Label & gt; Create Thumbnails & lt; / Labels & gt; & Lt; / Div & gt; & Lt; Id = "sizeThumbnailInput" name = "sizeThumbnail" style = "display: none" & gt; & Lt; Option value = "0" & ​​gt; Small (max 100x100px) & lt; / Options & gt; & Lt; Option value = "1" & gt; Apocalypse (max 250x250px) & lt; / Options & gt; & Lt; Option value = "2" & gt; Large (maximum 620x620px) & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br> & Lt; Input type = "submit" value = "upload" / & gt; & Lt; / Form & gt; Public class FileUploadHandler HttpServlet {Private Final String UPLOAD_DIRECTORY = "g: \\ Point" provides;

servlet

  private boolean thumbnails; @ Override secures zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String path1 = ""; String path2 = ""; String path = ""; If (request.getParameter ("thumbnail")! = Null & request.getParameter ("thumbnail"). Equals ("at")) {thumbnail = true; } // Process only if its multilevel content (ServletFileUpload.isMultipartContent (request)) {{list & lt; FileItem & gt; Multiparts = New servile file (new disk file item (FACTORY)). ParseRequest (request); (File item item: Multipurpose) {System.out.println (item.getFieldName ()); If (! Item.isFormField ()) {string name = new file (item.getName ()). GetName (); If (item.getName (). Length () & lt; 3 || item.getSize () & lt; 3) {request.setAttribute ("Message", "File is incorrect or not assigned."); Request (request / response); Return; } Path1 = UPLOAD_DIRECTORY + File.Sseparator + name; Item.write (new file (path 1)); If (thumbnail) {path2 = UPLOAD_DIRECTORY + File.Sseparator + "thumbnail_" + item.getName (); Resize Picture Replacement = Resize New Image (Path 1, Path 2, Resize Image resPicture.resize ();} Path = Path 1 + "\ n" + Path2;}} Request.setAttribute ("Message", " File upload successfully \ n "+ path);} hold (ex before) {request.setAttribute (" message "," file failed to upload "); ex.printStackTrace ();}} other {request.setAttribute ( "Message", "Sorry this servlet only handles file upload requests");} Request.getRequestDispatcher ("/ index.jsp") forwarded (request, response);}}  

java.lang.NullPointerExceptio N

  if (request.getParameter ("thumbnail")! = Blank and request.getParameter ("thumbnail"). Equals ("on") ) { 

If you are condition1 & condition2 , always Two situations are evaluated (in your example the ultimate "thumbnail" may be null ). You will need to use the condition1 & amp; amp; amp; amp; Condition2 will be evaluated if condition1 is true

Regards,


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -