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

applet db access mediated by jsp db access

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic