File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Web App. Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Web App. Question" Watch "Web App. Question" New topic
Author

Web App. Question

Gabe Newell
Greenhorn

Joined: Dec 07, 2004
Posts: 19
Hey Ranch members,

I am developing a web application and going to use Java. The web application is for a local charity that helps disadvanteged people from all walks of life by giving them free IT access and training. Their current system is MS Access database which was not fully relational nore has the essential data needed for the proposed system. I am doing this project for my dissertation for my IT degree. I was going to do this with PHP but I was fed up of how much hassle it is to maintain as the presentation and business logic is stuck together. The system hasn't got much concurrency issues as there is only 40 users. To view what the fuctionality of the system, go to the URL:

http://www.jamesaperry.co.uk/ukonline/

To view the ERD of the schema that I've designed for them:

http://www.jamesaperry.co.uk/ukonline/lds.html

I have read about using JSP/Servlets and I am wanting to develop using this tecnology. I like the idea of the MVC architecture where the presentation is seperate from the business logic. This web application isn't very complex.

I am not sure how to approach it. I've read several JSP/Servlets books and I am not sure do I use just JSP? Do I use the MVC Architecture? Shall my JSP use scripting? custom tags? Do I need EJB Beans? What's the best way to connect to my MySQL DB?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
EJB are not needed.
Use JSP for displaying your data only. Use JSTL and maybe a few custom tags in the JSPs instead of scriptlets.

To retrieve the data use normal Java classes called from servlets (which then can prepare the data for the JSPs to show as well as process form data from the JSPs for storage in the database).

A simple system would have a central controlling servlet which forwards requests to other servlets as they come in based on knowhow about where they come from and what they want to do (you could use a single request attribute to indicate the desired destination for example).
Those servlets then process the request, retrieve and store data, and prepare the output. They then forward to the proper JSP which shows the data and the cycle starts again.


42
Gabe Newell
Greenhorn

Joined: Dec 07, 2004
Posts: 19
Originally posted by Jeroen Wenting:
EJB are not needed.
Use JSP for displaying your data only. Use JSTL and maybe a few custom tags in the JSPs instead of scriptlets.

To retrieve the data use normal Java classes called from servlets (which then can prepare the data for the JSPs to show as well as process form data from the JSPs for storage in the database).

A simple system would have a central controlling servlet which forwards requests to other servlets as they come in based on knowhow about where they come from and what they want to do (you could use a single request attribute to indicate the desired destination for example).
Those servlets then process the request, retrieve and store data, and prepare the output. They then forward to the proper JSP which shows the data and the cycle starts again.



Many thanks Jeroen for the prompt reply and putting me in the right direction! I have a question though regarding your recommendation. The question may be due to ignorance but I was wondering why you would have one main controller servlet where you could have the requests forwarded specifiaclly to where the main controller would take them?
Allan Christensen
Greenhorn

Joined: Oct 21, 2003
Posts: 24
Originally posted by James Perry:

Many thanks Jeroen for the prompt reply and putting me in the right direction! I have a question though regarding your recommendation. The question may be due to ignorance but I was wondering why you would have one main controller servlet where you could have the requests forwarded specifiaclly to where the main controller would take them?


Hi James,

I suggest that you have a look at the description of the FrontController Design Pattern (http://java.sun.com/j2ee/patterns/FrontController.html). It explains the rationale for your question.

Kind regards,
Allan
Gabe Newell
Greenhorn

Joined: Dec 07, 2004
Posts: 19
Originally posted by Allan Christensen:


Hi James,

I suggest that you have a look at the description of the FrontController Design Pattern (http://java.sun.com/j2ee/patterns/FrontController.html). It explains the rationale for your question.

Kind regards,
Allan


Thanks, that URL helped. When I retrieve data from my DB schema, lets for example, a customer table. What is the best practise to output this data in a JSP? Would I have to create and populate a Customer bean for each record from the customer table and then store the beans in a collection array, then put the Customer bean collection into a implicit object for the JSP to read from?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
that is the usual way of doing things.
Another way would be to fill a HashMap with the data for each record (keyed to some string, say a field name) and put all those in a List.

It amounts to the same thing but saves you from creating that bean (which may be overkill if it's a very simple bean with only 2 or 3 textfields).
Gabe Newell
Greenhorn

Joined: Dec 07, 2004
Posts: 19
Originally posted by Jeroen Wenting:
that is the usual way of doing things.
Another way would be to fill a HashMap with the data for each record (keyed to some string, say a field name) and put all those in a List.

It amounts to the same thing but saves you from creating that bean (which may be overkill if it's a very simple bean with only 2 or 3 textfields).


Thanks yet again Jeroen!

What is the best practise to populate beans? The only way I know at the moment is by using the beans utitlity class from jakarta commons.

All MVC code I have seen by googling is where the main container distributes teh request straight to the JSP. Does any one know any good books or web sites to show me code and examples of how I use the MVC to direct to other sub-containers?

You don't know how much this has been helping me. I've been as no JSP/Servlet book tells you the best strategy to developing a small Java web app with a back-end DB.
[ January 30, 2005: Message edited by: James Perry ]
Gabe Newell
Greenhorn

Joined: Dec 07, 2004
Posts: 19
Some has recommended using struts for this proposed java web application's MVC achitecture. Is this a good or bad idea?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Personal opinon: avoid. Get to know how web apps work before deciding when or if to employ a framework.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web App. Question
 
Similar Threads
Design Question
Difference between JSP and SERVLET??
Disadvantages of servlet?
Difference between MVC1 and MVC2
JSP to Access 2000 database