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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With