Note that there are some explanatory texts on larger screens.

plurals
  1. POusing org.apache.commons.fileupload to upload an image in mysql database but calling the servlet gives a blank white page
    primarykey
    data
    text
    <p>I want to upload details of a hoarding in mysql database with an image using .jsp and servlet but when i call my servlet it gives a blank page..</p> <p>My .jsp</p> <pre><code>&lt;form action="HoardingProfile" method="post" enctype="multipart/form-data"&gt; &lt;table style="height: 100%; width:100%;"&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Location&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;input type="text" class="tx bk" name="txtLocation" placeholder="Location" required="yes"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Size&lt;/h3&gt; &lt;/td&gt; &lt;td class="padd10" style="width: 50%;"&gt; &lt;input class="tx bk" type="text" name="txtSize" placeholder="Size" required="yes"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Owner Name&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;input type="text" class="tx bk" placeholder="Owner Name" required="yes" name="txtName"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Contact No.&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;input type="text" class="tx bk" placeholder="Number" required="yes" name="txtNumber"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Address&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;textarea class="tx bk2" placeholder="Address" required="yes" name="txtAddress"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 15%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Picture&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;input type="file" name="file" id="file"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 50%;"&gt; &lt;h3&gt;Google map&lt;/h3&gt; &lt;/td&gt; &lt;td style="width: 50%;"&gt; &lt;textarea class="tx bk2" placeholder="Google Map iframe" name="txtMap"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 02%"&gt; &lt;td&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="height: 10%;"&gt; &lt;td class="tdleft" style="width: 80%;"&gt; &lt;input class="btn" type="submit" name="Add" value="Save" &lt;/td&gt; &lt;td style="width: 20%;"&gt; &lt;input class="btn" type="reset" value="Reset" &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>and my servlet</p> <pre><code> PrintWriter out = response.getWriter(); try { // Apache Commons-Fileupload library classes DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload sfu = new ServletFileUpload(factory); if (! ServletFileUpload.isMultipartContent(request)) { System.out.println("Sorry. No file uploaded"); return; } // parse request List&lt;FileItem&gt; items = sfu.parseRequest(request); out.print(items); FileItem txtLocation = (FileItem) items.get(0); String location = txtLocation.getString(); out.println(location); FileItem txtSize = (FileItem) items.get(1); String size = txtSize.getString(); out.println(size); FileItem txtName = (FileItem) items.get(2); String name = txtName.getString(); out.println(name); FileItem txtNumber = (FileItem) items.get(3); String number = txtNumber.getString(); out.println(number); FileItem txtAddress = (FileItem) items.get(4); String address = txtAddress.getString(); out.println(address); // get uploaded file FileItem file = (FileItem) items.get(5); // Connect to Oracle Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/opm?zeroDateTimeBehavior=convertToNull","root",""); con.setAutoCommit(false); PreparedStatement ps = con.prepareStatement("insert into hprofile(location,size,owner,address,phone,deleted,img) values(?,?,?,?,?,?,?)"); ps.setString(1, location); ps.setString(2, size); ps.setString(3, name); ps.setString(4, number); ps.setString(5, address); // size must be converted to int otherwise it results in error ps.setBinaryStream(6, file.getInputStream(), (int) file.getSize()); ps.executeUpdate(); con.commit(); con.close(); out.println("Proto Added Successfully. &lt;p&gt; &lt;a href='listphotos'&gt;List Photos &lt;/a&gt;"); } catch(Exception ex) { out.println( "Error --&gt; " + ex.getMessage()); } finally { out.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload