• 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

Web App. Question

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gabe Newell
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some has recommended using struts for this proposed java web application's MVC achitecture. Is this a good or bad idea?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personal opinon: avoid. Get to know how web apps work before deciding when or if to employ a framework.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic