• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Importing java.swing.JFileChooser in a jsp

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use Swing in a JSP. JSP is a templating technology to create HTML pages to send to the browser.
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I missed the given link the first time; thanks for opening the topic back up. I am reading the FAQ now.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic