Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.awt.HeadlessException

Tags:

java

JFileChooser chooser = new JFileChooser();
JDialog dialog=new JDialog();
dialog.setAlwaysOnTop(true);
/*System.out.println("is always on top?"+dialog.isAlwaysOnTop());*/
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showOpenDialog(dialog);

String path = null;

if(returnVal == JFileChooser.APPROVE_OPTION) {

    path=chooser.getSelectedFile().getAbsolutePath();

}

I have written this code in Servlet's doGet method.when i deployed in linux server getting following exception:

java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)

Does anyone know how to over come this?

like image 308
shiva tatikonda Avatar asked Sep 27 '26 01:09

shiva tatikonda


2 Answers

HeadlessException

Thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse.

like image 178
MariuszS Avatar answered Sep 28 '26 15:09

MariuszS


Your HTML form should have something like this:

<form action="upload" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" />
</form>

Then, using Apache Commons FileUpload, you can process the uploaded file in your Servlet. See their User Guide and FAQ for more information.

like image 32
mthmulders Avatar answered Sep 28 '26 15:09

mthmulders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!