I have a Serious problem. Question is: java.awt.HeadlessException
Now the problem is, I wrote the same code before a month and it worked fine in Windows 7 & NetBeans 7.1 Difference is that he wrote code in a servlet But i was write the in a Java file & then call the method from servlet.
BELIEVE ME IT'S 100% WORKS.
But now i am in Windows 8 & NetBeans 7.3 Only this two is changed.Now it is not working gives a Headless Exception. What can i do???
Now please tell me how to upload a file? I need full directory path, It will save in database.
Register.jsp:
<a href="UploadUserImage">
  <input type="button" class="button round blue image-right ic-upload text-upper" value="Upload" name="upload"/>
</a>
<font style="font-family: Times New Roman; font-size: 16px; color: #2a2e36; font-style: italic;"><%= image %></font>
<input type="hidden" value="images/Member/<%= image %>" name="image"/>
UploadImage.java(Servlet):
String image="images/"+new UploadFile().Upload();
request.getRequestDispatcher("Register.jsp?image="+image).forward(request, response);
UploadFile.java:
public class UploadFile
{
File file;
public String Upload()
{
    try 
    {
    final JFileChooser fc = new JFileChooser();
    String[] extensions={"jpg", "png", "gif"};
    FileNameExtensionFilter filter=new FileNameExtensionFilter("Images", extensions);
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    //fc.setCurrentDirectory(new File("C:\\tmp"));
    fc.setApproveButtonText("Upload");
    int retVal = fc.showOpenDialog(new JPanel());
    file=fc.getSelectedFile();
    String src,dst;
    src=file.getAbsolutePath();
    dst="C:\\Users\\SHUVAM KAYAL\\Documents\\NetBeansProjects\\BookShopManagment\\BookShopManagment-war\\web\\images\\Member\\"+file.getName();
    copy(new File(src), new File(dst));
    } 
    catch (IOException ex) 
    {}  
    catch(NullPointerException e)
    {}
    return file.getName();
}
public void copy(File sourceLocation , File targetLocation) throws IOException {
    if (sourceLocation.isDirectory()) {
        if (!targetLocation.exists()) {
            targetLocation.mkdir();
        }
        String[] children = sourceLocation.list();
        for (int i=0; i<children.length; i++) {
            copy(new File(sourceLocation, children[i]),
                    new File(targetLocation, children[i]));
        }
    } else {
        InputStream in = new FileInputStream(sourceLocation);
        OutputStream out = new FileOutputStream(targetLocation);
        // Copy the bits from instream to outstream
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }
}
}