File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Importing java.swing.JFileChooser in a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Importing java.swing.JFileChooser in a jsp" Watch "Importing java.swing.JFileChooser in a jsp" New topic
Author

Importing java.swing.JFileChooser in a jsp

Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
Configuration:
MyEclipse Enterprise Workbench
Version: 6.5.1 GA

I am creating a web application using jsp's. I have the import statement in a page directive as follows:

<%@page import = java.swing.JFileChooser %>

The error message is: The import java.swing cannot be resolved

I thought perhaps I should set a vm argument, but I am puzzled as to what type of run configuration to create. The vm argument I think I would need to use is:

-vm C:\Program Files\Java\jre1.6.0_05\bin\javaw.exe

I have worked with Java applications before; but you have to select a "main" for them, and the jsp does not have a main. I do not know where to specify a jdk so that the import statement would compile.

I hope I have given enough information. I have been using Google and this site; but I'm just not finding the information.

Thank you so much.
[ August 14, 2008: Message edited by: Mary Taylor ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

You can't use Swing in a JSP. JSP is a templating technology to create HTML pages to send to the browser.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
I want to have my user upload a file to a MySql database. What is the best approach? I thought HTML was just for display, but jsp could be used for code segments. I wanted to display a JFileChooser for the user to select the file to upload.

I saw code on the web to import JFileChooser in a jsp so that is why I tried it.

Thank you very much; if this needs to be in another forum, please let me know then.

Thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Originally posted by Mary Taylor:
I want to have my user upload a file to a MySql database. What is the best approach?
There is an entry in the JSP FAQ on this very subject.

I thought HTML was just for display, but jsp could be used for code segments.
HTML is the display component, but you will use the file input element of HTML to initiate the upload. The server-side code takes care of receiving the file. See the FAQ entry.

I wanted to display a JFileChooser for the user to select the file to upload.
You cannot. You need to rely upon the browser and the HTML file control as mentioned above.

I saw code on the web to import JFileChooser in a jsp so that is why I tried it.
There are also pictures of alien dissections on the web. (In other words, that example is probably bogus.)

Check out the FAQ entry and post back with any questions.
[ August 14, 2008: Message edited by: Bear Bibeault ]
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
Sorry I missed the given link the first time; thanks for opening the topic back up. I am reading the FAQ now.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

The reason it wouldn't work is because any Swing component you might add would be displayed on the server where the Java is running. That's not going to be of much use to your clients sitting in front of their browsers remotely.

The post you found on the web is not viable.
Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
Would it make sense from a design perspective to use the JFileChooser in a servlet? I guess not since that would be on the server ...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Exactly. Swing and web apps do not mix.

Your choices essentially are:
  • HTTP file upload (as described in the FAQ)
  • signed applet (scary to users)
  • write your own fat client and ditch the browser
  • Mary Taylor
    Ranch Hand

    Joined: Sep 11, 2000
    Posts: 319
    Thanks very much. I was on a team that wrote such a fat client a few years ago; but I wasn't doing the design so I'm having to think it through this time for myself. I appreciate your patience.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Importing java.swing.JFileChooser in a jsp