Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-07-2012, 07:06 PM   PM User | #1
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
JApplet opening local file for reading

I'm trying to get a web based Java Applet to open a user's excel file from their local computer for reading only. It work's of course when I run it as an application from my local computer, but the second I try to run it from a web page it show's the dialog but won't open the file.

I figure it has to do with security and all of that, but I'm not sure. Here is my code, any thought's on how I can get this thing fixed? Everything else work's just great, it's the opening the file I'm missing and I can't find anything on this searching for the past 20 min. on Google.

Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        File file = chooseExcelFile();
        // do nothing if open dialog was cancelled
        if (file == null) {
            return;
        }

        // loading long excel tables may be time consuming, so use wait cursor
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        Sheet sheet = readExcelSheet(file);
        if (sheet != null) {
            displaySheet(sheet, jTable1);
        }

        setCursor(Cursor.getDefaultCursor());

        stat.setText("Importing data...");
        stat.setVisible(true);

        value = 100 / Double.parseDouble(Integer.toString(jTable1.getRowCount()));
        //System.out.println(value);
        //System.out.println(jTable1.getRowCount());

        int confirm = JOptionPane.showConfirmDialog(null, "Are you sure you wish to import this file into your store?");
        if (confirm == JOptionPane.YES_OPTION) {
            new Thread () {
                public void run () {
                    startImp();
                }
            }.start();
        }
    }

private File chooseExcelFile () {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new XLSFilter());

        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            return chooser.getSelectedFile();
        }
        // cancel was clicked
        return null;
    }
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 07:08 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Have you signed the applet? The security won't let you open resource on a localmachine until its been signed and accepted by the user.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 07:15 PM   PM User | #3
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
I thought I had, that's just it

Attached is an SS of what my signing screen look's like, I'm using Netbeans by the way.

Attached Thumbnails
Click image for larger version

Name:	Selection_001.jpg
Views:	94
Size:	48.0 KB
ID:	11260  
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 07:48 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Do you have jarsigner.exe available? Run jarsigner -verify yourjar.jar to see if its signed and verified.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 07:55 PM   PM User | #5
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
This is what I get:

Quote:
jar verified.

Warning:
This jar contains entries whose signer certificate will expire within six months.

Re-run with the -verbose and -certs options for more details.
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 07:56 PM   PM User | #6
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
Verbose:

Quote:
589 Wed Jun 06 15:26:54 CST 2012 META-INF/MANIFEST.MF
615 Wed Jun 06 15:26:54 CST 2012 META-INF/NB-JWS.SF
786 Wed Jun 06 15:26:54 CST 2012 META-INF/NB-JWS.DSA
0 Wed Jun 06 15:26:56 CST 2012 META-INF/
sm 2354 Wed Jun 06 15:26:54 CST 2012 META-INF/INDEX.LIST
sm 525 Wed Jun 06 15:26:54 CST 2012 impExcel$1.class
sm 670 Wed Jun 06 15:26:54 CST 2012 impExcel$2.class
sm 652 Wed Jun 06 15:26:54 CST 2012 impExcel$3.class
sm 903 Wed Jun 06 15:26:54 CST 2012 impExcel$XLSFilter.class
sm 24363 Wed Jun 06 15:26:54 CST 2012 impExcel.class

s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
i = at least one certificate was found in identity scope
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 08:07 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Looks good to me.
Lets go back to the original problem. What happens when you open the chooser? Can you navigate the file system and actually select a file to use?
Also, when you load the applet it does ask for security confirmation and you accepted correct?
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 08:14 PM   PM User | #8
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
Hmm. I open the browser, load the HTML file (which loads JNLP just so you know), it asks for security confirmation and I accept. Then I click my button to pull up the select dialog, I can navigate and everything just fine, no problem's at all. I then select the file and click ok, just like I do when running as a regular app intead of applet. When running as an app it starts the process. When running as an applet nothing happen's, it just closes the dialog and that's it.

I should mention, I am using Ubuntu to do this on, Chrome testing. But I also tested on FF, but that shouldn't matter since it's not so much the browser but the JRE. I do have IcedTea installed rather than JDK since Ubu's new repo's don't have JDK by default, but IcedTea. Don't know if that would cause problem's.
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 08:20 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I hate debugging applets when only they are the problem :/
Lets see what happens with this:
PHP Code:
        JOptionPane.showMessageDialog(null"Execute file chooser");
        
File file chooseExcelFile();
        
// do nothing if open dialog was cancelled
        
if (file == null) {
            
JOptionPane.showMessageDialog(null"File resulted in null.");
            return;
        }
        
JOptionPane.showMessageDialog(null"File looks good to this point"); 
Which of those do you get?
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 08:30 PM   PM User | #10
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
:facepalm:!!!

I tell ya, more times than not I wanna do that ha ha. I had my keybinding for this project for clean and build set to only build and it wasn't replacing the old JAR with my new one, so my browser was running off of my older JAR that had NO action to the button at all!!!

I tell ya sometimes ha ha ha. So I re-did my keybinding to a clean and build and now it's working just fine

Thank's fou, sorry for the brain fart ha ha
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-07-2012, 08:42 PM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No worries, glad you got it solved!
Fou-Lu is offline   Reply With Quote
Old 06-08-2012, 04:11 PM   PM User | #12
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
Quick question, I'm having a heck of a time with my JDBC connect. When I do it with localhost it works fine, but when I use the domain name it doesn't work and the app breaks and no longer does anything at all when I click the button.

But, when I use localhost as my jdbc connection string, even when it's uploaded to my site, it connect's to my local PC's DB, not the server's. I expect this since Java runs the app on client side. So how do I fix this conundrum :S

I know the domain allow's MySQL external access, I have enabled it and checked it from mysql from my local machine, so no problem there.
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-08-2012, 04:32 PM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Write a server side handler and use RMI, SOAP or another type of communication to pass requests and responses between them to handle all the dbms actions. You can just rewrite the connection to point to that of the dbms, but I don't like that since the applet codebase can be retrieved by the client in its entirety, and picked enough through you can probably retrieve the username and password.
Fou-Lu is offline   Reply With Quote
Old 06-08-2012, 04:43 PM   PM User | #14
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
Hmm, don't like that idea, as you said it kind of leaves things out there

Now I have the old problem again, nothing has changed but the connection string's. Plus I took it back to use localhost instead just to make sure, no go.

Now it just doesn't bring up the choose dialog again. I am PMing you the link so I don't have to paste it publicly here. I don't know what I did :S ha ha
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Old 06-08-2012, 04:52 PM   PM User | #15
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
I just added an optionpane for the SQL exception error, so you might have to refresh it to get that, it's throwing it seem's a timeout error :|
__________________
"FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
http://www.microtronix-tech.com -- Web design and programming
jfreak53 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:01 AM.


Advertisement
Log in to turn off these ads.