s2sh 통합 실례 Struts2.0 Spring2.6 Hibernate3.2
Struts2 Spring2.6、Hibernate3.2 :
:MyEclipse 8.5、Tomcat 6.0、MySql
:
1. WEB , s2sh( , );
2. struts2 jar , WEB-INF lib jar
commons-fileupload.jar
commons-io.jar
freemarker.jar
javassist.jar
ognl-2.6.11.jar
struts2-core-2.0.14.jar
struts2-spring-plugin-2.0.14.jar
xwork-2.0.7.jar
3. Spring ( MyEclipse Spring Capabilities …)
:
1) Spring version:Spring 2.5
2) Select the libraries to add the buildpath:
Spring 2.5 AOP Libraries
Spring 2.5 Core Libraries
Spring 2.5 Persistence Core Libraries
Spring 2.5 Persistence JDBC Libraries
Spring 2.5 Web Libraries
3) JAR Library Installation:
Copy checked Library contents to project folder (TLDs always copied)
Next
4) Spring Folder:WebRoot/WEB-INF
Finish
4. Hibernate ( MyEclipse Hibernate Capabilities …)
:
1)Hibernate Specification:Hibernate3.2
2)Select the libraries to ad to the buildpath:Hibernate 3.2 Core Libraries Hibernage 3.2 Annoations
3)JAR Library Installation:Copy checked Library Jars to project folder and add to build-path
Next
4) :Spring configuration file(applicationContext.xml) Next
5) :Existing Spring configuration file
SessionFactory Id: sessionFactory Next
6)Bean Id:dataSource
DB Driver: Hibernate。Next
7) SessionFactory( Create SessionFactory class?)
8)Finish。
5. struts.xml , src struts.xml , :
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<package name="default" extends="struts-default">
<action name="registerAction" class="RegisterAction">
<result name="fail">/login.jsp </result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
6. web.xml , :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Struts2 Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- Struts2 -->
<filter>
<filter-name>Struts2.0</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2.0</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Struts2 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
7.
1). , s2sh, User
2). MyEclipse , MyEclipse Database Explorer
3). , New( ,Driver Name s1sh, , ),, Next, , (Display the selected Schemas), Add , , , ;
s1sh , Open connection, s2sh TABLE, TABLE, User , Hibernate Reverse Engineering( ), Java src folder src , Java Package bean , , Next, , , Next, , Finish, 。
8. Action
src , "com.beyondsoft.action"( , com , struts action ), action RegisterAction.java, :
package com.beyondsoft.action;
import java.util.List;
import com.beyondsoft.bean.User;
import com.beyondsoft.bean.UserDAO;
import com.opensymphony.xwork2.ActionSupport;
public class RegisterAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String userName;
private String password;
private UserDAO userDAO;
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() {
userDAO.save(new User(userName,password));
return "success";
}
}
10. , login.jsp, :
<%@ page language="java" pageEncoding="gb2312"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title> </title>
</head>
<body>
<center>
<div id="register">
<s:form action="registerAction">
<s:textfield label=" " name="userName"></s:textfield>
<s:password label=" " name="password"></s:password>
<s:submit value=" "></s:submit>
</s:form>
</div>
</center>
</body>
</html>
, struts2 , form 。form RegisterAction.java , RegisterAction.java struts.xml name "registerAction”, action "loginAction"。 name RegisterAction.java userName password 。
11. 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/s2sh"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/beyondsoft/bean/User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="RegisterAction" class="com.beyondsoft.action.RegisterAction">
<property name="userDAO">
<ref bean="UserDAO" />
</property>
</bean>
<bean id="UserDAO" class="com.beyondsoft.bean.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
sam-2.2.3.jar cglib-2.1.3.jar
Struts2 Spring2.6 Hibernate3.2 , 。
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
thymeleaf로 HTML 페이지를 동적으로 만듭니다 (spring + gradle)지난번에는 에서 화면에 HTML을 표시했습니다. 이번에는 화면을 동적으로 움직여보고 싶기 때문에 입력한 문자를 화면에 표시시키고 싶습니다. 초보자의 비망록이므로 이상한 점 등 있으면 지적 받을 수 있으면 기쁩니다! ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.