- 论坛徽章:
- 0
|
struts2.0.11+hibernate3.0.25.ga+spring2.0.7+maven2
struts2+hibernate+spring+mvn2
今天写了一个struts2.0.11+hibernate3.0.25.ga+spring2.0.7+maven2的小示例,遇到了不少的小问题,害得我连数据库系统概论都没上的下去真郁闷,要知道十五十六周就考试了阿,所以决定从下周开始暂时告别心爱的J2EE了,权力准备复习阿,不过东西也不能丢,贴出来,呵呵:麻雀虽小,但五脏俱全阿!!配置文件:
web.xml:
Archetype Created Web Application
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
org.springframework.web.context.ContextLoaderListener
applicationContext.xml:
User.hbm.xml
org.hibernate.dialect.MySQLDialect
true
20
20
struts.xml
/index.jsp
/welcome.jsp
/error.jsp
User.hbm.xml
globalmessage.properties
page.title=hello world
welcome=你好,欢迎
globalmessage_zh_CN.properties
page.title=hello world
welcome=\u4f60\u597d\uff0c\u6b22\u8fce
LoginAction.java
package cn.lyxs;
import com.opensymphony.xwork2.Action;
public class LoginAction implements Action
{
public String username;
public String password;
public String tip;
public UserManager userManager;
public UserManager getUserManager(){
return this.userManager;
}
public void setUserManager(UserManager userManager) {
this.userManager=userManager;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return password;
}
public void setTip(String tip)
{
this.tip=tip;
}
public String getTip()
{
return tip;
}
public String execute() throws Exception
{
userManager.addUser(getUsername(),getPassword());
if(getUsername().equals("liushaoqiong"))
{
setTip("hehe,success!");
return SUCCESS;
}
else
{
return ERROR;
}
}
}
User.java
package cn.lyxs;
import java.io.Serializable;
public class User implements Serializable
{
public int id;
public String username;
public String password;
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return id;
}
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return password;
}
}
UserDao.java
package cn.lyxs;
public interface UserDao
{
public void save(User user);
}
UserDaoHibernate.java
package cn.lyxs;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class UserDaoHibernate extends HibernateDaoSupport implements UserDao
{
public void save(User user)
{
getHibernateTemplate().save(user);
}
}
UserManagement.java
package cn.lyxs;
public interface UserManager
{
public void addUser(String username,String password);
}
UserMenegmentImpl.java
package cn.lyxs;
public class UserManagerImpl implements UserManager
{
public UserDao userDao;
public void setUserDao(UserDao userDao)
{
this.userDao=userDao;
}
public void addUser(String username,String password)
{
User u=new User();
u.setUsername(username);
u.setPassword(password);
userDao.save(u);
}
}
index.jsp
Message:
welcome.jsp
welcome success
success!
error.jsp
error
An error has occurrence
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cn.lyxs spring_struts2 war 1.0-SNAPSHOT spring_struts2 Maven Webapp http://maven.apache.org junit junit 3.8.1 test org.apache.struts struts2-core 2.0.11 org.springframework spring 2.0.7 org.apache.struts struts2-spring-plugin 2.0.11 org.hibernate hibernate 3.2.5.ga org.springframework spring-hibernate3 2.0.7 spring_struts2 org.mortbay.jetty maven-jetty-plugin 6.1.5
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/51541/showart_423386.html |
|