java - Form Parameter Value Not being fetched -


i making web application using jsp , servlets.in form tried upload file , enter value in textbox.here form :

<form method=post action="sharingfile" name="form1" id="form1" enctype="multipart/form-data">    <input type="file" name="file" value="file">   <input type="text" name="totalshares" size="20">   <input type="submit" value="next"> </form>   

and in sharingfile servlet wrote following code :

        string n = request.getparameter("totalshares");          servletfileupload upload = new servletfileupload(new diskfileitemfactory());         arraylist<string>filenamess=new arraylist<string>();         list<fileitem> files = new servletfileupload(new diskfileitemfactory()).parserequest(request);         out.println(files.size());         iterator it=    files.iterator();         while(it.hasnext()){          fileitem fi=(fileitem)it.next();          if (fi.isformfield()) {             continue;         }                        filenamess.add(fi.getname());         //system.out.println("filename: " + fi.getname());         inputstream is= fi.getinputstream();         fileoutputstream fos=new fileoutputstream("c:\\users\\admin\\desktop\\sharedcrpto1\\web\\shareddocuments\\"+fi.getname());         int x=is.read();          while(x>=0){             fos.write((byte)x);             x=is.read();             system.out.println("reading");             }          }         out.println(n);         out.println(filenamess.get(0)); 

but give value of n null.what can reason ?how resolve ?

you cant values of other parameters if use form type enctype="multipart/form-data" . need iterate this

for regular form field, interested in name of item, , string value. might expect, accessing these simple.

// process regular form field if (files.isformfield()) {     string n=request.getparameter("totalshares"); } 

for file related ,

for file upload, there several different things might want know before process content. here example of of methods might interested in.

// process file upload if (!files.isformfield()) {     string fieldname = item.getfieldname();     string filename = item.getname();     string contenttype = item.getcontenttype();     boolean isinmemory = item.isinmemory();     long sizeinbytes = item.getsize();     ... } 

hope helps !


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -