This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Design problem web, application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Design problem web, application" Watch "Design problem web, application" New topic
Author

Design problem web, application

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

I don't know the best approach to this problem. I'm building a web application JSP, Servlets, MYSQL with tomcat container.

The adminstration is in a normal Application to support integration with other desktop application and printing drag and drop and so on.

I want to use the same Objects in the application and JSP. What is the best approach.

Do I have to serialize all objects in the desktop application to communicate with servlets?

I don't have direct access to the mysql server because the port is closed just with servlets over port80. Anyone has suggestion on best approach

// Mathias


SCJP1.4
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Sending serialized objects back and forth is one approach; another is to make the admin app just a "thin client" with everything happening on the server; the server would provide a separate, rich interface (via web services, perhaps) which the admin app would use to communicate with it. Personally I'd choose this latter approach.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I always like pictures. See if this looks like what Ernest said:

The browser uses standard HTTP and gets back HTML. I usually like a servlet that receives the request, delegates to a plain Java object that interacts with the services, and then forwards to a JSP that builds the HTML response.

The Swing client does all its own presentation so it doesn't need HTML. It uses HTTP GET and POST again to communicate with a servlet. This servlet delegates to a plain Java object that interacts with the services, but then returns XML.

The biggest difference might be the "thing" that converts service output to HTML in one case and XML in the other. Another difference is that the second servlet can be a lot simpler.

This is such a common scenario that there are many tools to help you expose services as web services and consume them from the client end. On the other hand, it's really very easy to build your own and probably worth the education you'd get the first time around.

Having fun yet?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Thanks!

That all sound good but to be frank i don't really understand exactly what you are talking about. Perhaps I'm not quite that skilled in java yet.

I don't really have to use JSP because it is not a "real" web application
It is an applet that is signed. The applet interacts with servlets on another webserver. I have control over both of the servers.

What I mean is the users only use the applet. Drag and drop files drags boxes etc in the applet. The data needs to be saved to database. I can't communicate with the database directly from the applet because the users won't open the port in their firewall so it needs to be done over port 80.

// Mathias
Louis Moloney
Ranch Hand

Joined: Feb 06, 2007
Posts: 59
maybe im missing something here, but why not:

1. send the data from the applet to a servlet (HTTP port 80).
2. get the servlet to write the data to the database

then no need to mess around with any firewalls on client machines.


Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
How do you communicate from the applet to a server now? With HttpURLConnection? In that case, it's working just as the "fat client" path I drew above.
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

Yes I use HTTPURLConnection to communicate with servlets. I set the content type to post and receive java objects. Rather tedious to copy all classes that needs to be serialized from servlet to applet though.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Rather tedious to copy all classes that needs to be serialized from servlet to applet though.


Why is that? How do you "serialize" them across the wire? If you find XML too painful I won't disagree. Look at JSON for a simpler alternative.
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
I implement the Serializable interface and post them from applet to servlet. In the serlvet I receive the response cast the data and do the logic. Often I post back an object so that the applet knows that all was ok.
 
jQuery in Action, 2nd edition
 
subject: Design problem web, application