By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

image error in jsf: The system cannot find the file specified

P: 26
i tried to upload image but it prints error

Photo0017.jpg (The system cannot find the file specified)


Expand|Select|Wrap|Line Numbers
  1.  
  2. import org.apache.myfaces.custom.fileupload.UploadedFile;
  3.  
  4.  
  5. public class UploadBean {
  6. private UploadedFile uploadedFile;
  7. public UploadedFile getUploadedFile() {
  8. return uploadedFile;
  9. }
  10. public void setUploadedFile(UploadedFile uploadedFile) {
  11. this.uploadedFile = uploadedFile;
  12. }
  13. public String getFileName() {
  14. return fileName;
  15. }
  16. public void setFileName(String fileName) {
  17. this.fileName = fileName;
  18. }
  19. public Blob getDbImage() {
  20. return dbImage;
  21. }
  22. public void setDbImage(Blob dbImage) {
  23. this.dbImage = dbImage;
  24. }
  25. private String fileName;
  26. private Blob dbImage;
  27.  
  28. public String upload()
  29. {
  30.  
  31. int k = 0;
  32.  
  33. PreparedStatement ps = null;
  34. Connection con = null;
  35. try
  36. {
  37. Class.forName("com.mysql.jdbc.Driver");
  38. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tet", "root", "");
  39. File imgfile = new File(uploadedFile.getName());
  40.  
  41.  
  42. //System.out.println(“Name: ” + imgfile.getName());
  43. FileInputStream fin = new FileInputStream(imgfile);
  44.  
  45. String sql = "INSERT INTO upload_image (IMAGE,Image_name,image_length) VALUES(?,?,?)";
  46. ps= con.prepareStatement(sql);
  47. ps.setBinaryStream(1,fin,(int)imgfile.length());
  48. ps.setString(2, imgfile.getName());
  49. ps.setLong(3, uploadedFile.getSize());
  50.  
  51.  
  52.  
  53.  
  54.  
  55. k = ps.executeUpdate();
  56.  
  57.  
Expand|Select|Wrap|Line Numbers
  1. <h:form id="welcomeForm" enctype="multipart/form-data">
  2.     <h:outputText value="Here is a File upload example."/>
  3.  
  4. <t:inputFileUpload value="#{UploadBean.uploadedFile}" size="20" />
  5. <h:commandButton value="Load the file" action="#{UploadBean.upload}" />
  6.  
  7.  
  8.  
  9.   </h:form>
  10.  
  11.  
  12.  
Dec 25 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.