File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HELP! Applet's trouble with Servlet's response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HELP! Applet Watch "HELP! Applet New topic
Author

HELP! Applet's trouble with Servlet's response

Dan Fishman
Greenhorn

Joined: Jun 18, 2005
Posts: 7
HELP! Will pay $ if you help me.
I have an applet that allows a user to enter a database server URL, username, password, and SQL string, then send them to a servlet that will respond by sending back the resultset in Micro$haft EXCEL, that is being launched from the browser. But it doesn't work. I know the servlet gets the input data, but I think the problem is I don't know how to force the applet to delegate the reponse to the browser that the applet is launched from. I don't expect the applet to try to "open" the response in EXCEL, but I expect THE BROWSER to open the response in EXCEL. That I believe is the main problem. My problem is I need to explicitly force the applet to delegate or shut itself off temporarily then let the browser parse the EXCEL output from the servlet. I don't know how to do this! I have a similar program that works but it is just simple HTML communicating with servlet. Perhaps it is impossible to do this with an applet??!! I'm pretty sure my problem isn't with my servlet code because it is simply outputting data in EXCEL MIME type, the problem lies with my applet code. Please help!

Here's the applet source code:



Now here's the servlet source code:



Thanks in advance.

-Dan
[ June 19, 2005: Message edited by: Dan Fishman ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Dan,

Welcome to JavaRanch!

You can't do this with URLConnection. Instead of using serialization and all that fancy stuff, change your servlet to take just plain old CGI-type parameters encoded in the URL, and them use the AppletContext.showDocument() method to submit the URL containing those parameters to the servlet. The document that the servlet returns will be fielded by the browser. Use the optional second parameter to prevent the applet from being replaced. For this to work, of course, the servlet will have to use a Content-type that the browser recognizes as an Excel spreadsheet, and the browser has to be configured to launch Excel.

Don't want yer money, but you can clean out behind the pig pen if'n y'all want to help out.


[Jess in Action][AskingGoodQuestions]
Dan Fishman
Greenhorn

Joined: Jun 18, 2005
Posts: 7
Hi Ernest. Thanks! I was afraid of that. But, for security reasons, I prefer to POST my parameters rather than display them within the URL. I don't want my or other's password displayed in the URL. Furthermore, isn't there also a limit to how long my parameters can be? What if I have a long SQL string? Sorry for the dumb questions.

-Dan
Dan Fishman
Greenhorn

Joined: Jun 18, 2005
Posts: 7
Here's the code to make it work now just in case anyone's interested. I don't have much experience with the GET method. It sure was a learning experience. The problem I ran into was that it doesn't like carriage returns. I had to create a function to remove carriage returns in the SQL statement. That was the only stumbling block I ran into. The rest of was pretty easy.


[ June 19, 2005: Message edited by: Dan Fishman ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Dan,
One tip that will probably get you more help on this site.

Whenever posting more than a line or two of code, wrap it in the UBB code tags (there is a button on the edit screen that will create them for you). This preserves your indenting and makes your code a lot easier to read. This usually results in more people reading it and thus... more help.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dan Fishman
Greenhorn

Joined: Jun 18, 2005
Posts: 7
So folks. Is there a way to send the request data using POST method? Anyone? Using the GET method as was suggested works fine, but I can't send long SQL statements and furthermore, I am not allowed to use certain characters that are commonly used in SQL statements. Along with these issues and also because the password is visible, I am hoping someone can suggest an alternative method. Thanks.

-Dan
Dan Fishman
Greenhorn

Joined: Jun 18, 2005
Posts: 7
Wow no response! But alas, I found a way to use POST method. I modified the original applet to communicate with the servlet that will handle my query request (execute SQL, create resultset, save resultset as text file). Then I have it invoke another servlet that I created whose sole purpose is to open the file and launch it within the browser as an EXCEL file.

Here's the applet code:


Here's the SQLServletSerialized code that handles my query request:


Finally, here's the code for the servlet that just opens the resultset textfile as an EXCEL file within your browser:


Just FYI, the codes above are not thread safe and assumes Windows style directory system. I'm sure someone can do better...

Have a nice day,
Daniel

[ June 29, 2005: Message edited by: Dan Fishman ]

[ June 29, 2005: Message edited by: Dan Fishman ]

[ June 29, 2005: Message edited by: Dan Fishman ]
[ July 14, 2005: Message edited by: Dan Fishman ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP! Applet's trouble with Servlet's response