MySSH整合




com.zyl.action
--------------------com/zyl/action/DeleteAction.java
package com.zyl.action;

import com.zyl.po.User;
import com.zyl.service.IUserService;
import com.zyl.service.impl.UserServiceImpl;

public class DeleteAction {

private User user;
private Long id;
private IUserService userService;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public IUserService getUserService() {
return userService;
}

public void setUserService(IUserService userService) {
this.userService = userService;
}

public String execute() {
System.out.println(id);
userService.delete(id);
return "allUsers";
}
}

--------------------com/zyl/action/FindAllUsersAction.java
package com.zyl.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.zyl.service.IUserService;

public class FindAllUsersAction {
private IUserService userService;
public void setUserService(IUserService userService) {
this.userService = userService;
}
public String findAllUsers() {

Map request = (Map) ActionContext.getContext().get("request");
request.put("list", userService.findAllUsers());
return "allUsers";
}
}

--------------------com/zyl/action/LoginAction.java
package com.zyl.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.zyl.po.User;
import com.zyl.service.IUserService;

public class LoginAction extends ActionSupport {
private User user;
private IUserService userService;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public void setUserService(IUserService userService) {
this.userService = userService;
}

public String login() {

Boolean isFound = userService.validateLogin(user.getUsername(), user
.getPassword());
if (isFound == true) {
return SUCCESS;
} else {
return "input";
}
}




}

--------------------com/zyl/action/SaveAction.java
package com.zyl.action;

import com.zyl.po.User;
import com.zyl.service.IUserService;

public class SaveAction {

private User user;
private IUserService userService;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public void setUserService(IUserService userService) {
this.userService = userService;
}

public String save() {
User users = new User(user.getUsername(), user.getPassword());
Boolean isSaved = userService.save(users);
if (isSaved == true) {
return "allUsers";
} else {
return "input";
}
}
}

--------------------com/zyl/action/UpdateAction.java
package com.zyl.action;

import com.zyl.service.IUserService;

public class UpdateAction {
private Long id;
private String username;
private String password;
private IUserService userService;

public void setUserService(IUserService userService) {
this.userService = userService;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

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 update() {
userService.update(id, username, password);
return "allUsers";
}

}

--------------------com/zyl/action/UpdateRedirectAction.java
package com.zyl.action;

import com.zyl.service.IUserService;
import com.zyl.service.impl.UserServiceImpl;

public class UpdateRedirectAction {
private Long id;
private IUserService userService;

public void setUserService(IUserService userService) {
this.userService = userService;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String updateRedirect() {
userService.updateRedirect(id);
return "update";
}
}

--------------------com/zyl/dao/IUserDao.java
package com.zyl.dao;

import java.util.List;

import org.hibernate.HibernateException;

import com.zyl.po.User;

public interface IUserDao {
public void save(User user);

public List<User> findAllUsers()throws HibernateException;

public User findUserById(Long id);

public void delete(User users);

public void update(User user);

public User findByProperty(String username, String password) throws HibernateException;

}

--------------------com/zyl/dao/impl/UserDaoImpl.java
package com.zyl.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.zyl.dao.IUserDao;
import com.zyl.po.User;

public class UserDaoImpl extends HibernateDaoSupport implements IUserDao {

public List<User> findAllUsers()throws HibernateException {
return (List<User>) this.getHibernateTemplate().find(
"from User user order by user.id asc");
}

public User findUserById(Long id) {
User user = (User) this.getHibernateTemplate().get(User.class,id);
return user;
}

public void delete(User user) {
this.getHibernateTemplate().delete(user);
}

public void save(User user) {
this.getHibernateTemplate().save(user);

}

public void update(User user) {
this.getHibernateTemplate().update(user);

}

public User findByProperty(String username, String password)throws HibernateException {
User user = new User(username, password);
List<Long> queryResult = this
.getHibernateTemplate()
.find(
"select u.id from User u where u.username =? and u.password= ?",
new String[] { username, password });
if (queryResult!=null&&queryResult.size()==1) {
user.setId(queryResult.get(0));
return user;
} else {
return user;
}

}
}

--------------------
com.zyl.dao.Test
--------------------com/zyl/dao/Test/TestDao.java
package com.zyl.dao.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zyl.dao.IUserDao;
import com.zyl.po.User;

public class TestDao {
public static void main(String[] args) {

BeanFactory beanFactory = new ClassPathXmlApplicationContext(
"application*");
IUserDao userDao = (IUserDao) beanFactory.getBean("userDao");
User user = (User) beanFactory.getBean("user");
user.setUsername("zyl");
user.setPassword("123");
userDao.save(user);
}

}

--------------------com/zyl/dao/Test/UserDAOImplTest.java
package com.zyl.dao.Test;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zyl.dao.IUserDao;
import com.zyl.po.User;

public class UserDAOImplTest {

private static BeanFactory beanFactory;
private IUserDao userDao = null;
private User user =null;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
/*
beanFactory = new ClassPathXmlApplicationContext(new String[] {
"applicationContext.xml"});
*/
beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");
}

@AfterClass
public static void tearDownAfterClass() throws Exception {

beanFactory = null;

}

@Before
public void setUp() throws Exception {

userDao = (IUserDao) beanFactory.getBean("userDao");
user =(User) beanFactory.getBean("user");
}

@After
public void tearDown() throws Exception {

userDao = null;
}

@Test
public void findUserByPropertyTest() {

User user = userDao.findByProperty("zyl", "123");

Assert.assertNotNull("HQL错误", user);

Assert.assertNotNull("逻辑错误", user.getId().toString());

System.out.println(user);
}

// @Test
public void saveTest() {

user.setUsername("ddd");
user.setPassword("ddd");
userDao.save(user);
}
// @Test
public void findAllUsersTest(){
List<User> users = userDao.findAllUsers();
for (User user : users) {
System.out.println(user);
}
};
//@Test
public void findUserByIdTest(){
User user = userDao.findUserById(13L);
System.out.println(user.toString());

};
// @Test
public void deleteTest(){
User user = userDao.findUserById(4L);
userDao.delete(user);
Assert.assertNull("删除错误", user);

};
// @Test
public void updateTest(){
User user=userDao.findUserById(4L);
user.setUsername("yyy");
userDao.update(user);
System.out.println(user);
};

}

com.zyl.hiber.sessionfactory
package com.zyl.hiber.sessionfactory;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {

/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;

static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}

/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}

return session;
}

/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}

/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

if (session != null) {
session.close();
}
}

/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}

/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}

/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}

}
--------------------
com.zyl.po
--------------------com/zyl/po/User.java
package com.zyl.po;

import java.util.Date;

/**
* Users entity. @author MyEclipse Persistence Tools
*/

public class User implements java.io.Serializable {


private Long id;
private String username;
private String password;
public User() {
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
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 User(String username, String password) {
super();
this.username = username;
this.password = password;
}
public User(Long id, String username, String password) {
super();
this.id = id;
this.username = username;
this.password = password;
}
public String toString() {
return "User [id=" + id + ", username=" + username + ", password="
+ password + "]";
}

}
--------------------com/zyl/po/User.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping package="com.zyl.po">
<class name="User" table="T_USER" schema="zyl">
<id name="id" type="long">
<column name="ID" />
<generator class="identity" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="20" />
</property>
<property name="password" type="string">
<column name="PASSWORD" />
</property>
</class>
</hibernate-mapping>


com.zyl.service
--------------------com/zyl/service/IUserService.java
package com.zyl.service;

import java.util.List;

import com.zyl.po.User;


public interface IUserService {

public Boolean validateLogin(String username, String password);

public boolean save(User user);

public List<User> findAllUsers();

public void delete(Long id);

public void updateRedirect(Long id);

public void update(Long id, String username, String password);
}


com.zyl.service.impl
--------------------com/zyl/service/impl/UserServiceImpl.java


package com.zyl.service.impl;

import java.util.List;

import com.zyl.dao.IUserDao;
import com.zyl.po.User;
import com.zyl.service.IUserService;

public class UserServiceImpl implements IUserService {
private IUserDao userDao;
private User user;

public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
}

public IUserDao getUserDao() {
return userDao;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public Boolean validateLogin(String username, String password) {

user = userDao.findByProperty(username, password);
if (user.getId() == null) {
return false;
} else {
return true;
}
}

public List<User> findAllUsers() {

List<User> allUsers = userDao.findAllUsers();
return allUsers;
}


public void delete(Long id) {
System.out.println("service"+id);
User users = userDao.findUserById(id);
userDao.delete(users);
};

public void update(Long id, String username, String password) {
User user = userDao.findUserById(id);
user.setUsername(username);
user.setPassword(password);
userDao.update(user);
}

public void updateRedirect(Long id) {
user = userDao.findUserById(id);

};

public boolean save(User user) {
userDao.save(user);
User isfinded = userDao.findUserById(user.getId());
if (isfinded == null) {
return false;
} else {
return true;
}
}
}


--------------------com/zyl/service/impl/UsersServiceImplTestCase.java
package com.zyl.service.impl;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zyl.po.User;
import com.zyl.service.IUserService;

public class UsersServiceImplTestCase {

private static ApplicationContext beanFactory;
private IUserService userService;

@BeforeClass
public static void setUpBeforeClass() throws Exception {

beanFactory = new ClassPathXmlApplicationContext(new String[] {
"applicationContext.xml" });

}

@AfterClass
public static void tearDownAfterClass() throws Exception {

beanFactory = null;

}

@Before
public void setUp() throws Exception {

userService = (IUserService)beanFactory.getBean("userService");

}

@After
public void tearDown() throws Exception {

userService = null;

}

//@Test
public void validateLoginTest() {

User user = new User("zyl","123");

boolean userFound= userService.validateLogin(user.getUsername(),user.getPassword());

Assert.assertTrue("数据錯誤",userFound);
System.out.println(userFound);



}
//@Test
public void saveTest(){
User users = new User("234","123456");

boolean isSaved = userService.save(users);

Assert.assertTrue("插入失败",isSaved);

}
//@Test
public void findAllUserTest(){
userService.findAllUsers();
}
//@Test
public void deleteTest(){
Long id=13L;
userService.delete(id);
}

}


com.zyl.util
--------------------src/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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置事务管理器 -->
<bean name="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置事务传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置哪些类参与事务 -->
<aop:config>
<aop:pointcut id="allDaoMethod" expression="execution(* com.zyl.dao.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allDaoMethod"/>
</aop:config>

<import resource="beans-dao.xml"/>
<import resource="beans-service.xml"></import>
<import resource="beans-action.xml"></import>

</beans>
--------------------src/beans-action.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="DeleteAction" class="com.zyl.action.DeleteAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<bean id="LoginAction" class="com.zyl.action.LoginAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<bean id="SaveAction" class="com.zyl.action.SaveAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<bean id="UpdateAction" class="com.zyl.action.UpdateAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<bean id="UpdateRedirectAction" class="com.zyl.action.UpdateRedirectAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<bean id="FindAllUsersAction" class="com.zyl.action.FindAllUsersAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
</beans>

--------------------src/beans-dao.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="userDao" class="com.zyl.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
--------------------src/beans-service.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="user" class="com.zyl.po.User"></bean>
<bean id="userService" class="com.zyl.service.impl.UserServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>
</beans>
--------------------src/hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="connection.url">
jdbc:db2://192.168.25.230:50000/JSAMPLE
</property>
<property name="connection.username">zyl</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.ibm.db2.jcc.DB2Driver
</property>
<property name="myeclipse.connection.profile">zyl</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/zyl/po/User.hbm.xml" />

</session-factory>

</hibernate-configuration>
--------------------src/log4j.properties
log4j.rootLogger=ERROR,A1
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.TTCCLayout
--------------------src/struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="enterPck" extends="struts-default">
<global-results>
<result>/index.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="input" exception="java.lang.exception"></exception-mapping>
</global-exception-mappings>

<action name="LoginAction" class="LoginAction" method="login">
<result>/list.jsp</result>
<result name="input" type="redirect">/index.jsp</result>
</action>
<action name="SaveAction" class="SaveAction" method="save">
<result name="allUsers" type="redirect">/FindAllUsersAction.action
</result>
<result name="login" type="redirect">/index.jsp</result>
</action>
<action name="FindAllUsersAction" class="FindAllUsersAction" method="findAllUsers">
<result name="allUsers">/allusers.jsp</result>
</action>


<action name="DeleteAction" class="DeleteAction">
<result name="allUsers" type="redirect">/FindAllUsersAction.action
</result>
</action>


<action name="UpdateRedirectAction" class="UpdateRedirectAction" method="updateRedirect">
<result name="update">/update.jsp</result>
</action>

<action name="UpdateAction" class="UpdateAction" method="update">
<result name="allUsers" type="redirect">/FindAllUsersAction.action
</result>
</action>

</package>


</struts>

--------------------
/MySSH/WebRoot
--------------------WEB-INF/spring-form.tld
--------------------WEB-INF/spring.tld
--------------------WEB-INF/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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--
延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让action自己清除。
-->
<filter>
<filter-name>ActionContextCleanUp</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>ActionContextCleanUp</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
OpenSessionInViewFilter是Spring提供的一个针对Hibernate的一个支持类,其主要意思是在发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束,具体是通过一个Filter来实现的。
由于Hibernate引入了Lazy
Load特性,使得脱离Hibernate的Session周期的对象如果再想通过getter方法取到其关联对象的值,Hibernate会抛出一个LazyLoad的Exception。所以为了解决这个问题,Spring引入了这个Filter,使得Hibernate的Session的生命周期变长。
-->
<filter>
<filter-name>OpenSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInView</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>


<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>
<!-- spring的 配置文件在启动时,加载的项目目录下的applicationContext.xml-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


</web-app>

--------------------WebRoot/allusers.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'success.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<body>
<div align="center"> 欢迎
<s:property value="user.username" /></div>
<table align="center">
<form>
<s:iterator value="#request.list">
<tr>
<td>
<s:property value="id" />
</td>
<td>
<s:property value="username" />
</td>
<td>
<s:property value="password" />
</td>

<td>
<s:a href="DeleteAction.action?id=%{id}">delete</s:a>
</td>

<td>
<s:a href="UpdateRedirectAction.action?id=%{id}">update</s:a>
</td>
</tr>
</s:iterator>

</form>

</table>
<div align="center"><a href="save.jsp">保存用户</a></div>
</body>
</html>

--------------------WebRoot/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<form action="LoginAction.action" method="post">
<table align="center">
姓名:<input type="text" name="user.username"/><br>
密码:<input type="text" name="user.password"/><br>
<input type="submit" value="确定"/>
<input type="reset" value="重置"/>
</table>
</form>
</body>
</html>

--------------------WebRoot/list.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'list.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head><div align="center"> 欢迎
<s:property value="user.username" />
<table align="center">

<form>
<a href="FindAllUsersAction.action">所有用户</a>
</form>
</div>

--------------------WebRoot/save.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<form action="SaveAction.action" method="post">
<table align="center">
姓名:<input type="text" name="user.username" />
<br>
密码:<input type="password" name="user.password" />
<br>
<input type="submit" value="提交"><input type="reset" value="重置"/>
</form>
</table>
</body>
</html>

--------------------WebRoot/update.jsp


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'update.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>

<div align="center">更新用户</div>

<s:form action="UpdateAction">

<table>
<tr>
<td>
<s:hidden name="id" value="%{id}"></s:hidden>
</td>
</tr>

<tr>
<td>
<s:textfield name="username" value="%{username}" label="%{getText('username')}"></s:textfield>
</td>
</tr>

<tr>
<td>
<s:textfield name="password" value="%{password}" label="%{getText('password')}"></s:textfield>
</td>
</tr>
<tr>
<td>
<s:submit></s:submit>
</td>
</tr>
</table>

</s:form>

</body>
</html>
---------------------------------------------------------


pk ID BIGINT 8 否
USERNAME VARCHAR 20 是
PASSWORD VARCHAR 255 是

---------------------------------------------------------

MySSH
/MySSH/src
com.zyl.action
/MySSH/src/com/zyl/action/DeleteAction.java
/MySSH/src/com/zyl/action/FindAllUsersAction.java
/MySSH/src/com/zyl/action/LoginAction.java
/MySSH/src/com/zyl/action/SaveAction.java
/MySSH/src/com/zyl/action/UpdateAction.java
/MySSH/src/com/zyl/action/UpdateRedirectAction.java
com.zyl.dao
/MySSH/src/com/zyl/dao/IUserDao.java
com.zyl.dao.impl
/MySSH/src/com/zyl/dao/impl/UserDaoImpl.java
com.zyl.dao.Test
/MySSH/src/com/zyl/dao/Test/TestDao.java
/MySSH/src/com/zyl/dao/Test/UserDAOImplTest.java
com.zyl.hiber.sessionfactory
/MySSH/src/com/zyl/hiber/sessionfactory/HibernateSessionFactory.java
com.zyl.po
/MySSH/src/com/zyl/po/User.java
/MySSH/src/com/zyl/po/User.hbm.xml
com.zyl.service
/MySSH/src/com/zyl/service/IUserService.java
com.zyl.service.impl
/MySSH/src/com/zyl/service/impl/UserServiceImpl.java
/MySSH/src/com/zyl/service/impl/UsersServiceImplTestCase.java
com.zyl.util
/MySSH/src/applicationContext.xml
/MySSH/src/beans-action.xml
/MySSH/src/beans-dao.xml
/MySSH/src/beans-service.xml
/MySSH/src/hibernate.cfg.xml
/MySSH/src/log4j.properties
/MySSH/src/struts.xml
/MySSH/WebRoot
/MySSH/WebRoot/META-INF
/MySSH/WebRoot/META-INF/MANIFEST.MF
/MySSH/WebRoot/WEB-INF
/MySSH/WebRoot/WEB-INF/lib
/MySSH/WebRoot/WEB-INF/spring-form.tld
/MySSH/WebRoot/WEB-INF/spring.tld
/MySSH/WebRoot/WEB-INF/web.xml
/MySSH/WebRoot/allusers.jsp
/MySSH/WebRoot/index.jsp
/MySSH/WebRoot/list.jsp
/MySSH/WebRoot/save.jsp
/MySSH/WebRoot/update.jsp


---------------------------------------------------------


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值