开发者

Connecting Java Applet with Database

I've got a simple problem... I've got an Java applet running on my client machine which needs to communicate with a database at my end. I'm not sure how I go about it. There are nume开发者_如何学编程rous problems such as untrusted applet coming up. Please point me in the right direction. Thanks in advance.


You don't want to give an applet direct access to your database, rather you want a layer of business logic in between to prevent abuse. This is known as an multitier, (aka n-tier) system. Most web apps are designed in 3 tiers:

  • Presentation (in your case the Java applet)
  • Logic (business logic handling authentication, authorization, request validation, detailed processing, etc)
  • Data (your trusty database)

Java applets can communicate with your server in many ways, but you'll find it easier to deal strictly with HTTP requests returning simple data structures (like JSON or simple XML, SOAP was designed to be simple but is often accepted to be anything but). This way clients can easily get through firewalls, and if you redesign your front end using flash or html5 in the future, you're back end won't need to change as much.

You'll need to decide what makes most sense for your Logic tier, as there are many options in many languages. To be consistent in language, Java servlets running on a web server (e.g. Tomcat) can provide your logic layer, and there are many tools (e.g. Spring and Guice as a framework, Hibernate and MyBatis for ORM) to make writing and maintaining servlets easier - each with their own learning curve that you'll need to decide if it has value to you.

Also don't forget to search here on StackOverflow for more explanation and alternatives - this is hardly a comprehensive answer, but hopefully a pointer in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜