Myeclipse_ building an SSH framework

Source: Internet
Author: User

1. New Web project, and set the encoding to utf-8:xbyoa->properties->others->utf-8;

2. Add frame Environment: Junit + Struts2 + Hibernate + Spring;

"Add jar package + Copy config file + Modify profile"
"1" Xbyoa->bulid Path->add library->junit

"2" STRUTS2: Add Jar package, Struts.xml, Web. xml
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
Xml:

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
--------------------------------------------------------------------------------------------------------------- --------------------------------------------

Struts.xml:

<struts>
<!--configured for development mode--
<constant name= "Struts.devmode" value= "true"/>

<!--Configure the configuration name to action--
<constant name= "Struts.action.extension" value= "action"/>

<!--to configure the theme to simple---
<constant name= "Struts.ui.theme" value= "simple"/>

<package name= "Default" namespace= "/" extends= "Struts-default" >

</package>
<!--ADD packages here--
</struts>

"Hint" WINDOWS-&GT;PREFERENCES-&GT;XML.CATALOG-&GT;DTD file
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
"3" Hibernate: Add Jar Pack, Hibernate.cfg.xml, *.hbm.xml
Core Pack + must package + JPA + c3p0 + JDBC
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
"Hibernate.cfg.xml"
<session-factory>
<!--1 database connection Information 5 items--
<property name= "Hibernate.dialect" >org.hibernate.dialect.MySQLDialect</property>
<property name= "Hibernate.connection.driver_class" >com.jdbc.mysql.Driver</property>
<property name= "Hibernate.connection.url" >jdbc:mysql:///xbyoa</property>
<property name= "Hibernate.connection.username" >root</property>
<property name= "Hibernate.connection.password" >root</property>

<!--2 other configurations: Auto-build table shows SQL statement level two cache--
<property name= "Show_sql" >true</property>
<property name= "Hibernate.hbm2ddl.auto" >update</property>

<!--3 Import a mapping file--
</session-factory>
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
"4" Spring: Add Jar package, Applicationcontext.xml/beans.xml
Lib:spring.jar (Dist) + AQP: (Dynamic Agent: ASPECTJ) (subclass Agent: Cglib) + Commmons-logging,jar (log packet in jakarta-commons)
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
"Applicationcontext.xml"
<?xml version= "1.0" encoding= "UTF-8"?>

<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<!--automatically scan and assemble beans--
<context:component-scan base-package= "Xby.oa" ></context:component-scan>
</beans>

--------------------------------------------------------------------------------------------------------------- --------------------------------------------
3. Integrated SSH: Integrated STRUTS2 + Spring integrated Hibernater + spring;

--------------------------------------------------------------------------------------------------------------- --------------------------------------------
1, configure the spring Listener in Web. xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>

--------------------------------------------------------------------------------------------------------------- --------------------------------------------
2, add a jar package: struts2-spring-...
--------------------------------------------------------------------------------------------------------------- --------------------------------------------
Spring and STRUTS2 Integration
1,IOC managing objects: helping to inject and assemble objects
2,AOP Transaction Management
The pre-integration Struts2 is a reflection mechanism to generate the instance, and the Struts2 is to take the object from the spring container after the integration.

Hibernate and Spring Integration
1, Manage sessionfactory instances (only one required)
2, declarative transaction management

This configures a bean, which is equivalent to invoking its default construction method through reflection, and then specifying the property, which is equivalent to invoking the object's Seter method to inject the attribute into it.
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory" >
</property>
</bean>
--------------------------------------------------------------------------------------------------------------- --------------------------------------------

4. Resource classification:

5. Configure the log:
--------------------------------------------------------------------------------------------------------------- --------------------------------------------

Myeclipse_ building an SSH framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.