• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

HELP! Applet's trouble with Servlet's response

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dan Fishman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dan Fishman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic