File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes experts - please comment on a design issue 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 » Servlets
Bookmark "experts - please comment on a design issue" Watch "experts - please comment on a design issue" New topic
Author

experts - please comment on a design issue

Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
Dear experts,
I am doing a small mini-proj on servlet develpoment. The proj outline is below.
The 2 major components in my mini proj are:
1) User Iterface: A simple html form is displayed when the user types http://localhost:7001/wip. This is implemented in doGet method of the servlet.
a) On the form-level I perform simple validation (viz. ensure there are no empty fields). I am using javascript for doing this.

2)Server Side service: The servlet uses a cached database connection (using WLS) to fetch data from the database. It then formats the data into a html & sends it back to the client.
Now, at this point I have a question:
-{/b] When I write the code for doPost() I find myself doing the database activity i.e. generating sql & fetching data from database as well as formatting the data returned into HTML. Doing both in the same method gives a very shabby feel of doing things coz I am doing both DB activity as well the presentation at the same place (esp all those HTML code makes the code looks worse). In fact, they seem to be totally 2 different entites that could be dealt serperately. I feel that would be better.
[b]-
Also, if I could break my proj as sep entities (viz. one entity could take care of doing a DB work, other the HTML part & etc etc) & be able to call them from doPost then I guess that be easier to develop.
For doing this should I start learning EJB components or is there some other elegant to approach the whole thing.
Please note that I have started devloping using servlets recently. I don't have much idea about EJB. Experts please guide me. Also, I was thinking if I should be using JSP (which I've just read the into chapter). What I am basically asking is for the correct approach & design. PLease help.
Thanks in advance,
sat


- Sathvathsan Sampath
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Mixing a lot of HTML print statements with program logic bothers a lot of people about servlets. However, you don't have to do everything in one gigantic doPost method.
You might find it easier to debug if you put the SQL query construction and data fetch in a separate class. One advantage of this is you can test the logic of this class outside the servlet environment. You can use the JavaBean convention for that class and make life easier if you ever want to do JSP.
Bill

------------------
author of:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: experts - please comment on a design issue