Applet & Connection
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, February 25, 2004 08:45 AM

How can i pass a Connection Object from a JSP page to an Applet running in that JSP Page

Re: Applet & Connection

Posted By:   p_j  
Posted On:   Wednesday, February 25, 2004 09:46 AM

You can't "pass" the connection from the JSP page to the applet because the JSP Thread dies after the page is loaded. Any connections (which should have been closed by termination of the JSP page) will now be dead and unusable.



However since the applet exists and runs independently you CAN open another connection from the applet. You could specify the location to applet in a parameter tag e.g.











Remember though that firstly applet security prevents you from connecting to another host than the one which hosted the jsp/html page on which the applet resides. I.e. your applet must now communicate with mysite.com and cannot connect to mysitesdatasources.com



Also you must remember that a database/any other type of connection from an applet will be from the client side. (As opposed to from your server side in JSP). This is a big security liability because if you need to make connections oviously urls, usernames and passwords will need to be passed around. If they are IN the resulting html code or even in the applet code they can be reverse engineered. If you have to communicate with the backend from an applet I would suggest letting the applet comunicate with an intermiediary JSP page which does the connections instead.

e.g.

Your applet opens a url connection to htpp://mysite.com/appletcommunicator.jsp?parameters=Whatevere_you_want_to_pass



Then write a jsp page which comunicates with the backend using your parameters:



<%

String myData = request.getParameter("parameters");



sendToDb(doSomeManipulation(myData));

%>
About | Sitemap | Contact