1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)
 

Recent Questions

!!! JSP Frequently Asked Questions !!!

Q.How to upload an image from servlet/jsp into server from clients machine?

!!!Answer!!!- From Technical Expert

Image upload from JSP to Data Base step by step :

step 1 :
In the JSP
<form name="regform2" method="post" enctype="multipart/form-data">
<input type="file" name="ImageFile" id="ImageFile" onChange="uploadImage()"/>
</form>

java script :
function uploadImage(){
document.regform.action ="<%=request.getContextPath()%>/dfdmin?cmd=uploadimage";
document.regform.submit();
}


Step 2.
In the servlet - add the below code.
This will upload your image to server (D:\\) or In unix you can mention /home/user like that

String rtempfile = File.createTempFile("temp","1").getParent();
MultipartRequest multi = new MultipartRequest(request, rtempfile, 500000 * 1024);
File rnewfile=null;
rnewfile = new File("D:\\"+"jsp"+File.separator+"images"+File.separator+"uploadImage"+File.separator);
if(rnewfile.exists()){
}else{
rnewfile.mkdirs();
}

File f = multi.getFile("ImageFile");
System.out.println(f.getName());
FileInputStream fin =new FileInputStream(f);
RandomAccessFile r = new RandomAccessFile(rnewfile+File.separator+f.getName(),"rw");
filename = f.getName();
// FileOutputStream fos =new FileOutputStream(rnewfile);
byte sizefile[] = new byte[5000000];
fin.read(sizefile);
// fos.write(sizefile);
r.write(sizefile);
//fos.close();
r.close();
fin.close();

DAO.upload(f); // Call to DAO for insert image into database.

Step 3.

Then call to DAO to save this image to data base.
Insert into Database
public void upload(File f){
InputStream is = new FileInputStream(f);
String sql = " INSERT INTO image_upload (IMAGE) VALUES (?) ";
pStmt = conn.prepareStatement(sql);
pStmt.setBinaryStream(1, is, (int)(f.length()));
pStmt.execute();
conn.commit();
}



This will upload multipart file to your data base.

Note : get cos.jar from oreilly website


OR
if your server have already image file then just do below step




Code is here :
File f = new File("d:\\test.jpg");
InputStream is = new FileInputStream(f);
String sql = " INSERT INTO image_upload (IMAGE) VALUES (?) ";
pStmt = conn.prepareStatement(sql);
pStmt.setBinaryStream(1, is, (int)(f.length()));
pStmt.execute();
conn.commit();

This will work.

Answered By : null Replied Date : Jan 30 2014
Answer :


Answered By : null Replied Date : Jan 22 2014
Answer :


Answered By : gfhgf Replied Date : Mar 29 2013
Answer : hjhgjhg


Answered By : null Replied Date : Nov 2 2013
Answer :


Answered By : null Replied Date : Nov 1 2013
Answer :


Answered By : null Replied Date : Oct 12 2013
Answer :


Answered By : null Replied Date : Feb 5 2014
Answer :


Answered By : null Replied Date : Feb 6 2014
Answer :


Answered By : null Replied Date : Feb 11 2014
Answer :


Answered By : null Replied Date : Feb 12 2014
Answer :


Answered By : null Replied Date : Apr 27 2014
Answer :


Answered By : null Replied Date : May 6 2014
Answer :


Answered By : null Replied Date : May 6 2014
Answer :


Answered By : null Replied Date : May 12 2014
Answer :


Answered By : null Replied Date : May 18 2014
Answer :


Answered By : null Replied Date : Jun 5 2014
Answer :


Answered By : null Replied Date : Jun 6 2014
Answer :


Answered By : null Replied Date : Jun 6 2014
Answer :


Answered By : null Replied Date : Jul 10 2014
Answer :


Answered By : null Replied Date : Aug 1 2014
Answer :


Answered By : null Replied Date : Aug 2 2014
Answer :


Answered By : null Replied Date : Oct 14 2014
Answer :


Answered By : null Replied Date : Oct 21 2014
Answer :


Answered By : null Replied Date : Nov 3 2014
Answer :


Answered By : null Replied Date : Nov 4 2014
Answer :


Answered By : null Replied Date : Nov 12 2014
Answer :


Answered By : null Replied Date : Nov 19 2014
Answer :


Answered By : null Replied Date : Nov 20 2014
Answer :


Answered By : null Replied Date : Nov 20 2014
Answer :


Answered By : null Replied Date : Dec 18 2014
Answer :


Answered By : null Replied Date : Dec 20 2014
Answer :


Answered By : null Replied Date : Jan 23 2015
Answer :


Answered By : null Replied Date : Feb 2 2015
Answer :


Answered By : null Replied Date : Mar 6 2015
Answer :


Answered By : null Replied Date : Mar 24 2015
Answer :


Answered By : null Replied Date : Mar 24 2015
Answer :


Answered By : null Replied Date : May 16 2015
Answer :


Answered By : null Replied Date : May 22 2015
Answer :


Answered By : null Replied Date : May 25 2015
Answer :


Answered By : null Replied Date : May 26 2015
Answer :


Answered By : null Replied Date : May 28 2015
Answer :


Answered By : null Replied Date : Jun 17 2015
Answer :


Answered By : null Replied Date : Aug 26 2015
Answer :


Answered By : null Replied Date : Aug 28 2015
Answer :


Answered By : null Replied Date : Aug 31 2015
Answer :


Answered By : null Replied Date : Sep 20 2015
Answer :


Answered By : null Replied Date : Sep 20 2015
Answer :


Answered By : null Replied Date : Oct 15 2015
Answer :


Answered By : null Replied Date : Jan 4 2016
Answer :


Answered By : null Replied Date : Jan 6 2016
Answer :


Answered By : null Replied Date : Jan 16 2016
Answer :


Answered By : null Replied Date : Apr 14 2016
Answer :


Answered By : null Replied Date : Apr 17 2016
Answer :


Answered By : null Replied Date : Apr 18 2016
Answer :


Answered By : null Replied Date : Apr 19 2016
Answer :


Answered By : null Replied Date : Apr 26 2016
Answer :


Answered By : null Replied Date : Apr 28 2016
Answer :


Answered By : null Replied Date : Apr 30 2016
Answer :


Answered By : null Replied Date : May 5 2016
Answer :


Answered By : null Replied Date : Jul 7 2016
Answer :


Answered By : null Replied Date : Jul 7 2016
Answer :


Answered By : null Replied Date : Jul 12 2016
Answer :


Answered By : null Replied Date : Aug 18 2016
Answer :


Answered By : null Replied Date : Sep 29 2016
Answer :


Answered By : null Replied Date : Sep 30 2016
Answer :


Answered By : null Replied Date : Sep 30 2016
Answer :


Answered By : null Replied Date : Sep 30 2016
Answer :


Answered By : null Replied Date : Sep 30 2016
Answer :


Answered By : null Replied Date : Nov 26 2016
Answer :


Answered By : null Replied Date : Jan 18 2017
Answer :


Answered By : null Replied Date : Jan 20 2017
Answer :


Answered By : null Replied Date : Jan 31 2017
Answer :


Answered By : null Replied Date : May 23 2017
Answer :


Answered By : null Replied Date : May 29 2017
Answer :


Answered By : null Replied Date : Jul 6 2017
Answer :


Answered By : null Replied Date : Jul 18 2017
Answer :


 

You can also contribute to this answer:

Your Name:
Answer:

 
Ask Question and get answer from Expert.
View Answers List from Expert.

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy