This discussion is archived
5 Replies Latest reply: Jan 18, 2013 2:28 PM by DrClap RSS

Problem with JFileChooser Execution

985357 Newbie
Currently Being Moderated
I wanted to write a code using JFileChooser so that I can use File Selector as part of my application.
I took the sample code online and executed on my local machine. It worked fine. But when I deployed my code on Application server, I got surprised to see that after running my program, the File Chooser pop up comes on Application server machine and not on User Machine.
Please suggest.

Following is the piece of code which I got online and used in my application to launch File Selector.
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(true);
     
chooser.showOpenDialog(null);

Edited by: 982354 on Jan 16, 2013 6:08 PM
  • 1. Re: Problem with JFileChooser Execution
    PhHein Guru Moderator
    Currently Being Moderated
    That's no surprise, Swing components show up where you run them. You've chosen the wrong tools.
  • 2. Re: Problem with JFileChooser Execution
    Kayaman Guru
    Currently Being Moderated
    As PhHein said, you've got the wrong tools. If it only was so easy to magically transfer a GUI over network (you could install games on your application server, and people could just play them from home).

    Swing isn't going to help you here, you need to use either a ready made component in a web framework, or the standard HTML <input type="file">
  • 3. Re: Problem with JFileChooser Execution
    985357 Newbie
    Currently Being Moderated
    Thanks for the reply. I tried using Java <input type="file"> but the problem was to get the full path of the files with java script.
    Is there any other java program which could help me getting File Selector at client side.
  • 4. Re: Problem with JFileChooser Execution
    r035198x Pro
    Currently Being Moderated
    So you have a web application? Google "yourFrameworkName file upload" where yourFrameworkName is the name of the view technology you are using. Could be jsp, jsf, struts e.t.c
  • 5. Re: Problem with JFileChooser Execution
    DrClap Expert
    Currently Being Moderated
    982354 wrote:
    Thanks for the reply. I tried using Java <input type="file"> but the problem was to get the full path of the files with java script.
    I don't know what "java script" has to do with this. The <input type="file"> element is for the purpose of uploading a file. The server does not need the full path of the file being uploaded, in fact it doesn't need the name of the file at all. Perhaps you were still expecting that your server could use the full path of the client's file to access the file from the client? That isn't how it works. The server should simply process the data which comes along with the request, which is the contents of that file.

    And since it's evident that you're a beginner at this, I recommend that you don't try to write code to do that. It's way too complicated for you at this point and besides it's already been done properly by the Apache FileUpload project. Download their code and use it, if it's actually a file upload that you are trying to do.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points