Guest User

temp

a guest
Apr 23rd, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. String relativeWebPath = "/temp_image";
  2. UPLOAD_DIRECTORY = getServletContext().getRealPath(relativeWebPath);
  3. String UPLOAD = "";
  4.  
  5. PrintWriter out = response.getWriter();
  6. try
  7. {
  8. Class.forName("com.mysql.jdbc.Driver").newInstance();
  9. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shopbyway","root","");
  10. st = con.createStatement();
  11. st2 = con.createStatement();
  12. st3 = con.createStatement();
  13. }
  14. catch(Exception e)
  15. {
  16.  
  17. }
  18. //process only if its multipart content
  19. int count=0;
  20. String temp="";
  21. String file_name="A";
  22. String p_name="";
  23. String product_description="";
  24. String uploadFilePath="uploads\\";
  25. String user="";
  26. String n_cate="";
  27. String name="";
  28. String newp="";
  29. String category_name="";
  30. int p_id=0;
  31. int p_cate=0;
  32. int c_cate=0;
  33. int shop_id=0;
  34. int k=0;
  35. int price=0;
  36. int old=0;
  37. ResultSet rs,rs2;
  38. FileItem fileitem = null;
  39. String UPLOAD_DIR = "uploads\\";
  40. if(ServletFileUpload.isMultipartContent(request))
  41. {
  42.  
  43.  
  44. try {
  45. List<FileItem> multiparts = new ServletFileUpload(
  46. new DiskFileItemFactory()).parseRequest(request);
  47.  
  48. for(FileItem item : multiparts)
  49. {
  50.  
  51. if (item.isFormField())
  52. {
  53.  
  54.  
  55. if(item.getFieldName().equals("shop_name"))
  56. {
  57. temp = item.getString();
  58. shop_id = Integer.parseInt(temp);
  59.  
  60. }
  61. if(item.getFieldName().equals("p_cate"))
  62. {
  63. temp = item.getString();
  64. p_cate = Integer.parseInt(temp);
  65.  
  66. }
  67. if(item.getFieldName().equals("p_name"))
  68. {
  69. p_name = item.getString();
  70.  
  71. }
  72. if(item.getFieldName().equals("newp"))
  73. {
  74. newp = item.getString();
  75.  
  76. }
  77.  
  78.  
  79.  
  80. if(item.getFieldName().equals("product_description"))
  81. {
  82. product_description = item.getString();
  83.  
  84. }
  85.  
  86.  
  87. if(item.getFieldName().equals("price"))
  88. {
  89. temp = item.getString();
  90. price = Integer.parseInt(temp);
  91. }
  92.  
  93. if(item.getFieldName().equals("shop_owner"))
  94. {
  95. user = item.getString();
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102. }
  103.  
  104. if(!item.isFormField()){
  105. //out.println(item);
  106. fileitem = item;
  107. name = new File(item.getName()).getName();
  108.  
  109. file_name = item.getName();
  110. item.write( new File(UPLOAD_DIRECTORY + File.separator + name));
  111. //item.write( new File(uploadFilePath));*/
  112. }
  113.  
  114.  
  115. }
  116.  
  117. out.println("\nFile uploaded successfully");
  118. //response.sendRedirect("/shop_temp/index.jsp");
  119. } catch (Exception ex) {
  120.  
  121. }
  122.  
  123. }else{
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130. UPLOAD = file_name;
  131.  
  132. if(p_name.equals(""))
  133. {
  134. old=0;
  135. p_name = newp;
  136. }
  137. else
  138. {
  139. old=1;
  140.  
  141. }
  142. out.println(user+"<br>");
  143. out.println(shop_id+"<br>");
  144. out.println(p_name+"<br>");
  145. out.println(product_description+"<br>");
  146. out.println(price+"<br>");
  147. out.println(p_cate+"<br>");
  148. out.println(old+"<br>");
  149. String que = "insert into approval values(null,'"+user+"',"+shop_id+",'"+p_name+"','"+product_description+"',"+price+","+p_cate+",'"+UPLOAD+"',"+old+",0);";
  150. try
  151. {
  152. st3.executeUpdate(que);
  153. }
  154. catch(SQLException e)
  155. {
  156. }
  157. response.sendRedirect("/shop_temp/manage_products.jsp?mesg=We will verify your product with in 24 working hour");
Add Comment
Please, Sign In to add comment