error in loading image file
<p>uploadimage.html</p>

<pre><code>         &lt;html&gt;

   &lt;head&gt;&lt;title&gt;Image Upload&lt;/title&gt;&lt;/head&gt;

      &lt;body&gt;
&lt;form action="UploadImage" method="post" enctype="multipart/form-data" name="productForm" id="productForm"&gt;&lt;br&gt;&lt;br&gt;
    &lt;table width="400px" align="center" border=0 style="background-color:ffeeff;"&gt;
        &lt;tr&gt;
            &lt;td align="center" colspan=2 style="font-weight:bold;font-size:20pt;"&gt;Image Details&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align="center" colspan=2&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td&gt;Image Link: &lt;/td&gt;
            &lt;td&gt;
                &lt;input type="file" name="file" id="file"&gt;
            &lt;td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" name="Submit" value="Submit"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;

    &lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;

  &lt;/html&gt;
</code></pre>

<p>UploadImage.java</p>

<pre><code>   public class UploadImage extends HttpServlet{
          @Override
           public void doPost(HttpServletRequest request, 
          HttpServletResponse  response) throws ServletException, IOException {

    PrintWriter out = response.getWriter();

    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    out.println("request: "+request);
    if (!isMultipart) {
        out.println("File Not Uploaded");
    } else {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;

        try {
            items = upload.parseRequest(request);
            out.println("items: "+items);
        } catch (FileUploadException e) {
            e.printStackTrace();
        }
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();
            if (item.isFormField()){
                String name = item.getFieldName();
                System.out.println("name: "+name);
                String value = item.getString();
                System.out.println("value: "+value);
            } else {
                try {
                    String itemName = item.getName();
                    Random generator = new Random();
                    int r = Math.abs(generator.nextInt());

                    String reg = "[.*]";
                    String replacingtext = "";
                    out.println("Text before replacing is:-" + itemName);
                    Pattern pattern = Pattern.compile(reg);
                    Matcher matcher = pattern.matcher(itemName);
                    StringBuffer buffer = new StringBuffer();

                    while (matcher.find()) {
                        matcher.appendReplacement(buffer, replacingtext);
                    }
                    int IndexOf = itemName.indexOf(".");
                    String domainName = itemName.substring(IndexOf);
                    out.println("domainName: "+domainName);

                    String finalimage = buffer.toString()+"_"+r+domainName;
                    out.println("Final Image==="+finalimage);

                    File savedFile = new File("C:\\Users\\Nirmala\\Documents\\NetBeansProjects\\tabswitch\\web\\"+"images\\"+finalimage);
                    item.write(savedFile);
                    out.println("&lt;html&gt;");
                    out.println("&lt;body&gt;");
                    out.println("&lt;table&gt;&lt;tr&gt;&lt;td&gt;");
                    out.println("&lt;img src=images/"+finalimage+"&gt;");
                    out.println("&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;");

                    /*Connection conn = null;
                    String url = "jdbc:mysql://localhost:3306/";
                    String dbName = "test";
                    String driver = "com.mysql.jdbc.Driver";
                    String username = "root";
                    String userPassword = "root";
                    String strQuery = null;
                    String strQuery1 = null;
                    String imgLen="";

                    try {
                        System.out.println("itemName::::: "+itemName);
                        Class.forName(driver).newInstance();
                        conn = DriverManager.getConnection(url+dbName,username,userPassword);
                        Statement st = conn.createStatement();
                        strQuery = "insert into testimage set image='"+finalimage+"'";
                        int rs = st.executeUpdate(strQuery);
                        System.out.println("Query Executed Successfully++++++++++++++");
                        out.println("image inserted successfully");
                        out.println("&lt;/body&gt;");
                        out.println("&lt;/html&gt;");
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    } finally {
                        conn.close();
                    }   */
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
</code></pre>

<p>}</p>

<p>but i observed a strange thing....the image is not getting displayed.... image is getting created after it is being read in the servlet...please help me...</p>

<p>output is..
Text before replacing is:-LogoBMP.bmp domainName: .bmp Final Image===LogoBMP_726573791.bmp </p>
