免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 850 | 回复: 0
打印 上一主题 下一主题

struts2+hibernate+spring+mvn2 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-15 21:05 |只看该作者 |倒序浏览

                                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP