Showing posts with label struts. Show all posts
Showing posts with label struts. Show all posts

Tuesday, May 27, 2008

Simple JNDI Accessing MySQL Datasource

Base on the previous post, I have used the struts-config.xml to define the datasource to access to the MySQL database. The datasource class is code within the Action class (controller layer) and map to the struts-config.xml.

In order to improve the programming pratice, the datasource can be created via JNDI and the java code should be sit within the model layer. As a result, business logic will separate from the controller layer and making the Action class without knowing any relation with business class at all.

Click here to read more...

Monday, May 26, 2008

Struts - Database Access by Defining Datasource within the struts-config.xml

A sample program which connecting to the MySQL database to display the data. I am using the Struts framework to developed this program. The main idea is of this post is to use the struts-config.xml to define the datasource and using Action class to access and select the data.

Please bear in mind, the Action class which represent as controller layer, should not contain any business logic code and database access code. The best pratice is to apply the DAO mechanism by putting your business logic or database access code within the model layer.
The datasource should only define within the struts-config.xml when there is a limitation of connectivity to the database within the model layer. Alternative, you can use the JNDI to define the datasource and that would be the best recommendation in best pratice. However, that will be my next post on my blog.



Here are the summary of development been used.

  • Struts 1.2.9 framework

  • index.jsp, selectBook.jsp, SelectBookActionForm.java - view layer

  • SelectBookAction.java - controller layer

  • Book.java - data layer

  • Defining datasouce at struts-config.xml

  • MySQL database
Read more and download the code: Click here

Sunday, May 25, 2008

Struts: Build HTML Options Tag Elements from MySQL data

Some sample program developed using STRUTS framework to access the MySQL database and retrieve data to build the html options elements. This post is consider as an enhancement from the previous post Struts: HTML Options Tag Sample Code.

The previous post was hardcoded to build the html options tag. Meanwhile, this post will build the html options’ elements by retrieving data from MySQL database.

I have used the struts-config.xml to define the datasouce to access to the MySQL database.

Click here to read more.

Monday, May 19, 2008

Struts: HTML Options Tag Sample Code

I have been doing some research on the internet recently and notice not much of the sample code been provided to build the drop down menu using struts html option tag. Here are the sample program which I develop using Struts framework by applying the html options tag. The screenshot will look similar as below.



Please click here to view the code:
http://leejeok.wordpress.com/2008/05/14/struts-html-options-tag-sample-code/