my dog learned polymorphism*
The moose likes Applets and the fly likes  applet db access mediated by jsp db access  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark " applet db access mediated by jsp db access  " Watch " applet db access mediated by jsp db access  " New topic
Author

applet db access mediated by jsp db access

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

hi,

i have a web application that consists of jsp pages ,servlets & an applet.

for jsp & servlets i use the mysql jdbc driver jar to connect to mysql db -server side-.

we want also to access db from applet. - applet is client side -.
for security reasons the applet does not have direct sql access. we want i to be mediated by the JSP.

how can we use the server side JSP db connection for applet client side db access?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
I would strongly recommend not to use a JSP as the mediator between the applet and the DB - use a servlet. JSPs are meant for generating text, not for implementing control logic.

In the servlet I'd advise to use a connection pool (which the existing servlets and JSPs should already be using anyway). The pool can be made available to the servlets either through JNDI, or as a context attribute.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thanks for prompt reply,
yes that's exactly what i'm doing : i use a connection pool within my servlets(not jsp) to connect to mysql db.
now the issue is how can i make this connection pool object available to applet ?
i tried serializing it & sending it throw network from servlet to applet ; but this didn't worked because Connection java object can't be serialized.

do you have a suggestion ?

thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
Well, you said before that the applet shouldn't be using SQL directly, so even if it were possible to serialize a connection, it would not be the solution to your problem.

I'd suggest that the applet use HTTP requests to communicate to the servlet what information it needs, and that the servlet sends that information as part of the HTTP response. Use HTTPS instead of HTTP if the data is sensitive.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Originally posted by Ulf Dittmer:
Well, you said before that the applet shouldn't be using SQL directly, so even if it were possible to serialize a connection, it would not be the solution to your problem.

I'd suggest that the applet use HTTP requests to communicate to the servlet what information it needs, and that the servlet sends that information as part of the HTTP response. Use HTTPS instead of HTTP if the data is sensitive.


thanks,
that's what exactly i did: applet-servlet communication.
but as i said i couldn't send the connection pool object with HTTP,because it uses java sql Connection class and i got an error saying that Connection class can't be serialized.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
I can't quite tell if you're still trying to get this to work, but in case you are: it won't work. The connection exists on the server, and that's where it must be used. The applet sends plain text or HTTP parameters to the servlet, which then uses the pool to access the DB.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Thanks .
the solution of using HTTP applet-servlet comunication to query database is doable ; but i think it has a performance issue because of network traffic.am i right ?

i was thinking to use jndi to talk to driver from both servlet & applet.
is that possible ?
can someone show me an example of using jndi for this purpose: sharing a single connection pool between servlet & applet.
any other solution will be greatly appreciated
thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
the solution of using HTTP applet-servlet comunication to query database is doable ; but i think it has a performance issue because of network traffic.

I don't see why there should be a fundamental difference in network performance between an HTTP connection and a DB connection (which is based on TCP/IP as well). Any difference will likely be trumped by the time it takes to perform the server-side actions, so this is nothing to worry about.

i was thinking to use jndi to talk to driver from both servlet & applet. is that possible ?

No. Please give up the idea of somehow using the server-side connection in the applet - it just doesn't work.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

just for someone who ends up on this thread.the solution is indeed using servlet /applet communication .you send your parameters from applet to servlet and do the database manipulation in the servlet then return what ever results you want to applet

to my surprise this solution worked great and was very efficient & fast.

thanks for all .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet db access mediated by jsp db access