?
Solved

jsp sample code, mysql, first website

Posted on 2003-03-25
5
Medium Priority
?
292 Views
Last Modified: 2010-04-01
hi,
i need to create a website for a non-profit org and have a full db schema planned etc.  but i have seen many snippets of code all over the web, some that make DB calls within the jsp pages, other that use the mvc design paradigm and use struts, etc.  is there a place that i can get a starter code package that i can modify for my non-profit?

i just need to retrieve content from the DB and display it on the web using
Tomcat4.1, MySQL, and JDK1.4.  

I have learned that the best way to code is probably with a special Bean that is responsible for talking to the DB (Model) but I have failed to find ample sample code on the web of how to create a bean and call it from the JSP.

Any help would be appreciated.
Regards
0
Comment
Question by:mgupta1013
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 8205585
first make sure you have the mysql jdbc driver added to your classpath (for compilation) and tomcat/common/lib directory

you can get the jdbc driver from here:
http://www.mysql.com/downloads/api-jdbc-stable.html

here is a good example of a DB bean:
http://www.roseindia.net/jsp/usingbeansinjsp.htm

CJ
0
 

Author Comment

by:mgupta1013
ID: 8206379
that is a good example, but i thought that the JSP pages were not supposed to know anything about the underlying DB schema, correct?  It appears from that example that the JSP page actually defines the SQL and then just uses the bean to execute the SQL.

I thought that is not the correct way to program MVC 2, no?
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 225 total points
ID: 8206413
you can create helper methods that retrieve specific data and run the SQL for you inside that bean or another bean.  But the example above is a good start to atleast create a basic db access bean and you can use that to create other helper methods or other beans that completely hide the data access process - following DAO pattern.

CJ
0
 

Author Comment

by:mgupta1013
ID: 8206459
CJ,

Do you know how struts play into the picture.  I have downloaded struts pkg, and gone through a lot of docs, but I have failed to understand how people use them in the web deployment world.

Additionally, do you know a location/packaged suite of ready to use beans?

Thanks
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8211566
just search on google for jsp beans .. I am sure there are plenty.

a good resource is www.jspin.com

as far as struts goes, its pretty much providing a tag based approach to do MVC:
http://jakarta.apache.org/struts/userGuide/introduction.html#overview
good guide/tutorial sites:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html
http://developer.bluestone.com/scripts/SaISAPI.dll/Gallery.class/demos/trailMaps/index.jsp?sect=3&area=trail [tutorial]
http://www-106.ibm.com/developerworks/library/j-struts/?n-j-2151

CJ
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
The deadly train derailment that occurred recently in DuPont, Washington, raises a lot of questions. It was a new route, the first trip tested with passengers, and the train was travelling at 50 mph over the zone’s speed limit. Could IoT play a role…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question