Myeclipse integration using struts, hibernate, spring, a sample program

This article is taken from:

 Enterprise applications in java, ejb ejb powerful configuration with the complex and difficult to learn as well known. But in the past, what we do? Only the unpleasant task to learn ejb. Really little, "are aware of the angels fear to tread line of" spirit. With the positive changes in the form now, java continued popularity of open source, allowing developers to java ejb enterprise applications are no longer limited to the field. Here I describe how to use the main source of Spring  ,Hibernate  And the Struts framework to build a lightweight.  

  First, the overall structure description  

  In software engineering, in order to reduce module coupling, enhance the reusability of modules, hierarchical has been a widely adopted method. In fact, stratification also allows developers to focus on a particular level for development, enabling software developers finer division of labor, increase production efficiency (comparable to this point, Ford invented the assembly line production of automotive practice, responsible for all workers in specific parts of the production, final assembly).  

  An enterprise-class java application, is usually divided into the following layers: UI layer, business logic and data persistence layer, the domain object layer. The following briefly describes these layers are:  

1  . UI layer: responsible for user interaction, including: receiving a user's request, the processing results are returned to the user. Here we use struts to UI layer, although these events than Tapestry and JSF presentation layer technology, the driver, Struts design looks a little old fashioned, but it is still the de facto standard performance level, so we still use it.  

2  . Business Logic Layer: The main charge of specific business processes. Through Spring's IOC and AOP to realize various functions connected to the coupling  
3  . Data persistence layer: responsible for dealing with the underlying database. Here we use Spring Hibernate package to simplify the actual encoding operation. The major operation for the CRUD (create  ,read,update,delete  )  
4  . Domain object layer: a specific entity type, such as teachers, students, etc. These specific categories (Note: the need for the database in a Correspondence).  
  These are just a brief introduction of each layer and the layers corresponding to the division of open-source framework, to learn more about the layers of a layer of information, need access to struts  ,hibernate,spring  The official website.  
  Second, case study  
  Examples: a website login example of simple, but can explain how the coordination of all levels.  
  Tools: jdk1  .5,eclipse3.2,myeclipse5.0GA,mysql5.0,tomcat5.5  As these tools in the end how to install here I do not say we can not clear search the web search. Here are the steps:  
  Preparatory work: create a test with the mysql database, then create a user table, create two fields username and password. Script as follows  
USE `test`;

`id` int(11) NOT NULL auto_increment,
`username` varchar(30) NOT NULL default '',
`password` varchar(30) default '',

  Open myeclipse the database explore perspective  
  Right-click an empty area on the left, click the new button  

  Click the "configure database driver" to configure the database driver, you must have mysql's jdbc driver not to mysql's official website.  
  Test database configuration was successful.  

1 . Create a new web project in myeclipse

2  . The introduction of Spring Package  

Right Project Name

  Note: This can then add the spring in order to save the relevant package, so a one-time check all the packages. Select the Copy option, it will copy the package to  /WebRoot/WEB-INF/lib  Directory to facilitate the actual deployment of the future.  

3 . Add the hibernate package

  System will detect the project has added a Spring package, choose to use the Spring configuration file  

  Click next  
  Click next  
  Click next  
  Finally click the Finish button.  

4 Switch to the database explore view, right click on user table "Hibrnate Reverse Engineering"

  The following pop-up window  
  Click "next"  
  Then click finish  

View can be seen in the package under the src one more vo of the package name and the package of the four documents

  In order to more directly display layers, I also built a package called the dao of  ,  And to UserDAO  .java  Moved to the dao of  

  Also note the applicationContext  .xml  In the reference section of the UserDAO also be amended accordingly.  

5 . The establishment of business logic code

Create a new package called the service and then create a Service class in which the code is as follows

package service;
import java.util.List;
import vo.User;
import dao.UserDAO;
public class Service {
private UserDAO userDao;
public UserDAO getUserDao() {
return userDao;
public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
public boolean isValid(User user) {//  Determine whether the user is legitimate  
List result = userDao.findByExample(user);
if (result.size() > 0)
return true;
return false;
  At the same time in the applicationContext  .xml  Add the following configuration  
<bean singleton="false">
<property name="userDao">
<ref bean="userDao" />
6  . UI Layer Configuration  
  Add struts package, add the spring with the same method  
  Configuring struts  -config.xml  File, right-click a blank area of a new action  ,actionForm ,jsp

As set on the forward , Increased succeed to welcome .jsp,fail Go to login .jsp

WebRoot directory in a welcome .jsp File, display the user login information after the success of Welcome.

6 . To connect the struts and spring

6 . 1 modified struts -config.xml Note that some of the red font

<forward name="fail" path="/login.jsp" />
<forward name="succeed" path="/welcome.jsp" />

  Longer strut  -config.xml  Add the following code  

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
6.2  Modify applicationContext, add the following  
<bean name="/login"
<property name="service">
<ref bean="service" />
6.3  Changes LoginAction  .java  Part of the code, add a service variable, and its get  /set  Method (mainly for Spring IOC). Code:  

* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
package web.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import web.form.LoginForm;
import service.Service;
import vo.User;
* MyEclipse Struts Creation date: 09-27-2006
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp"
* scope="request" validate="true"
* @struts.action-forward name="fail" path="/login.jsp"
* @struts.action-forward name="succeed" path="/welcome.jsp"
public class LoginAction extends Action {
* Generated Methods
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
private Service service;
public void setService(Service service) {
this.service = service;
public Service getService() {
return service;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method
// stub
User user = new User();
if (service.isValid(user))
return mapping.findForward("succeed");
return mapping.findForward("fail");
  This point has been made a simple login. The remaining job is to package and distribute your app.  

  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Myeclipse integration using struts, hibernate, spring, a sample program

  • MyEclipse Spring Hibernate integration and development

    MyEclipse Hibernate Spring integration and development is how to proceed? Let us begin to explain it: MyEclipse Spring Hibernate integration of a development environment MyEclipse6.01GA, MySQL. MyEclipse Spring Hibernate integration of two, table str

  • Spring 3.0 + Struts 2.1 + Hibernate 3.3 integration framework summary

    Introduction: SSH framework a while to learn, and today the integration of SSH framework to do a summary. My steps are Spring à Hibernate à Sturts 2 MyEclipse 9.0 environment is used mainly to add functionality to support the way: (MyEclipse à add xxxx ca

  • MyEclipse development of SSH (Struts + Spring + Hibernate) started [with map]

    MyEclipse development of SSH (Struts + Spring + Hibernate) Getting Started March 6, 2008 at 11:24 (This reference from oksonic the " Struts + Spring + Hibernate practice (full) ") Source Download:

  • struts.spring.hibernate integration steps

    SSH integration process? struts, spring, hibernate integration steps: 1. Importing struts, spring, hibernate package necessary 2. In the web.xml to configure <context-param> <param-name> contextConfigLocation </ param-name> <para ...

  • struts2.1 + hibernate 3.2 + spring 2.5 Integration

    Create a new project in MyEclipse, based on j2ee5, according to the following steps: 1, class library: Struts: Commons-logging-xxxjar, freemarker-xxxjar, ognl-xxxjar, xwork-xxxjar, struts-2-core-xxxjar, struts2-spring-plugin-xxxjar Hibernate: Hibernate3.2

  • s2sh framework for integration of

    struts2, spring and hibernate integration of the development. The integration of the three main spring of this is to use the middle frame, up to integrate struts2, downward integration of hibernate. The specific configuration is as follows. struts-config.

  • Graphic MyEclipse configuration struts + hibernate + spring + FreeMarker

    The past few days to hibernate and spring looked good, the re-think some things struts, decided to look at three integrated together with, the presentation layer using struts + freemarker, business layer using spring, hibernate persistence layer processin

  • Struts + hibernate + Spring integration method

    Struts + hibernate + Spring integration method 1, in the project to import spring support, import Jar package are: Spring Core Libraries Spring ORM/DAO/Hibernate3 Libraries Spring AOP Libraries Spring Web Libraries 2, in the Spring configuration file to c

  • Struts-Spring-Hibernate Integration

    Struts-Spring-Hibernate Integration 6.6.1 Environmental structures and basic configuration Eclipse can we increase the Struts2.0, Spring2.0, Hibernate3.1 support, as follows: 1. To build a simple Struts2 Web Engineering 1) download and install the Struts2

  • MyEclipse configuration struts1.2 + hibernate + spring diagram

    The past few days to hibernate and spring looked good, the re-think some things struts, decided to look at three integrated together with, the presentation layer using struts + freemarker, business layer using spring, hibernate persistence layer processin

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries