Struts + Spring + Hibernate Integration

Posted on 2014/07/20, Updated on 2015/08/30

Update: For new software development or building a new website from ground-up, there is better design alternative instead of using the Struts framework. Using JSTL is a better alternative, and here is a post in Webpage development using JSTL, Javascript, and JQuery. For older webpage systems, created before 2014, the Java and Struts combination is popular, and therefore a lot of legacy systems runs using these technologies.

Let’s Remember these important files that are needed in configuration of a Java Web application.
( Which includes Spring, Hibernate, and Struts )

web.xml – Servlet class to URL mapping
applicationContext.xml – Spring mapping of Bean/Object injection
struts.xml – maps the defined action to the servlet ( action class is needed in struts ) to the result jsp
hibernate.cfg.xml– database connection such as JDBC name , user/password to access the database name is defined here
<classname>.hbm.xml – the database table hibernate mapping file

index.jsp – the initial action URL, the startpage

Steps:

1.) Define org.springframework.web.context.ContextLoaderListener as the listener and org.apache.struts2.dispatcher.FilterDispatcher as the filter in web.xml

2.) Basically Spring is used here to create the predefined values, as these can be done by using the bean property injection in applicationContext.xml

Here’s a detailed explanation at this site: http://www.tutorialspoint.com/struts_2/struts_spring.htm

Advertisements

Struts Basics

1.) Create a Form Class. This class must extend the org.apache.struts.action.ActionForm, the form class may just be fields with setters and getters.

2.) Create a Action Class ( the Controller ). This class must extend the org.apache.struts.action.* . Then override execute method where the request will be processed.

3.) In the struts-config.xml, define the Form Class and the Action Class here.

4.) In the web.xml file, define the org.apache.struts.action.ActionServlet and the struts-config.xml
struts-config.xml and web.xml should be in the same WEB-INF folder. Also iclude the “action” servlet mapping.

5.) Create the JSP page to render the web browser view.

See the details in this site:
http://www.mkyong.com/struts/struts-hello-world-example/