龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Jsp编程 >

ssi框架学习总结(mvc三层架构)(4)

时间:2014-09-14 11:31来源:网络整理 作者:网络 点击:
分享到:
UserDao.java : package com.broada.demo.dao; /** * @author smm */ import java.util.List; import com.broada.demo.entity.User; public interface UserDao {/** * 用户注册 * @param user * @return */pub

UserDao.java

package com.broada.demo.dao;
 
/**
 * @author smm
 */
 
import java.util.List;
 
import com.broada.demo.entity.User;
 
public interface UserDao {
	
	/**
	 * 用户注册
	 * @param user
	 * @return
	 */
	
	public boolean insertUser(User user);
	
	/**
	 * 根据用户名获取用户信息
	 * @param name
	 * @return
	 */
	
	public User queryByname(String name);	
}

UserDaoImpl.java

package com.broada.demo.daoImpl;
/**
 * @author smm
 */
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
 
import com.broada.demo.dao.UserDao;
import com.broada.demo.entity.User;
 
public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao{
 
 
 
	@Override
	public boolean insertUser(User user) {
		try {
			getSqlMapClientTemplate().insert("insertUser", user);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}	
	}
 
	@Override
	public User queryByname(String name) {
		// TODO Auto-generated method stub
		try {
			User user =(User) getSqlMapClientTemplate().queryForObject("selsectUser", name);
			return user;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
}

UserDaoServiceInter.java

package com.broada.demo.service;
 
/**
 * @author smm
 */
 
import com.broada.demo.entity.User;
 
public interface UserDaoServiceInter {
	
	/**
	 * 用户注册服务接口
	 * @param user
	 * @return
	 */
	
	public boolean insertUser(User user);
	
	/**
	 * 根据用户名获取用户信息接口
	 * @param name
	 * @return
	 */
	
	public User querybyname(String name);
}

UserDaoServiceImpl.java

package com.broada.demo.serviceImpl;
 
/**
 * @author smm
 */
 
import com.broada.demo.dao.UserDao;
import com.broada.demo.entity.User;
import com.broada.demo.service.UserDaoServiceInter;
 
public class UserDaoServiceImpl implements UserDaoServiceInter {
 
	private UserDao userdao;
	public UserDao getUserdao() {
		return userdao;
	}
	public void setUserdao(UserDao userdao) {
		this.userdao = userdao;
	}
	@Override
	public boolean insertUser(User user) {
		return userdao.insertUser(user);
	}
	@Override
	public User querybyname(String name) {
		// TODO Auto-generated method stub
		return userdao.queryByname(name);
	}
 
}

Index.jsp

<%@ page language="java" contentType="text/html; charset=utf8"
	pageEncoding="utf8"%>
	<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<link rel="stylesheet" type="text/css" href="css/ext-all.css" />
<link rel="stylesheet" type="text/css"
	href="css/ext-theme-classic-all.css" />
<script type="text/javascript" src="js/ext-all.js"></script>
 
 
<title>用户登陆</title>
<script type="text/javascript">
Ext.onReady(function(){
		initPanel();	 
	});
	
	initPanel=function(){
		 var formPanel = new Ext.FormPanel({
			  id: 'loginPanel',
			  labelWidth: 75, 
			  frame:true,
			  bodyStyle:'margin:0 auto',
			  width: 350,
			  defaults: {width: 250},
			  defaultType: 'textfield',
			  items: [{id: 'username',fieldLabel: '用户名',name:'name',allowBlank: false,blankText: '账号不能为空'},
			  {id: 'password', fieldLabel: '密 码',name:'password',inputType: 'password',allowBlank: false,blankText: '密码不能为空'}]
			     });
		var win = new Ext.Window({  
			  title:'登陆界面', 
			  width:380,
			  autoHeight: 'true',
			  resizable: false,
			  modal:true,
			  closeAction: 'hide',
			  buttonAlign:'center',
			  items:formPanel,
			  buttons:[{text: '登陆',handler: function(){land();}},
			      {text: '重置',handler: function(){
			        Ext.getCmp('username').setValue("");
			        Ext.getCmp('password').setValue("");
			        }},{text: '注册',handler: function(){register();}}]
			   });
			       
		win.show();
	};
	
	var win1;
	
	register = function(){	
		
		var registerPanel = new Ext.FormPanel({
		  id: 'registerPanel',
		  labelWidth: 75, 
		  frame:true,
		  bodyStyle:'margin:0 auto',
		  width: 350,
		  defaults: {width: 250},
		  defaultType: 'textfield',
		  items: [{id: 'registername',fieldLabel: '用户名',name:'name1',allowBlank: false,blankText: '账号不能为空'},
		  {id: 'registerpassword', fieldLabel: '登陆密 码',name:'password1',inputType: 'password',allowBlank: false,blankText: '密码不能为空'},
		  {id: 'registerpassword2', fieldLabel: '密码确认',name:'password2',inputType: 'password',allowBlank: false,blankText: '密码不能为空'},
		  {id: 'nichen',fieldLabel: '昵称',name:'nichen1'},
		  {id: 'address',fieldLabel: '地址',name:'address1'}]
		     });
		
		win1 = new Ext.Window({  
			  title:'注册界面', 
			  width:380,
			  autoHeight: 'true',
			  resizable: false,
			  modal:true,
			  buttonAlign:'center',
			  items:registerPanel,
			  buttons:[{text: '提交',handler: function(){login();}},
			      {text: '取消',handler: function(){win1.close();}}]
			   });
			       
		win1.show();
	};
	
	login=function(){
		var name = Ext.getCmp('registername').getValue(); 
		var password = Ext.getCmp('registerpassword').getValue();
		var password2 = Ext.getCmp('registerpassword2').getValue();
		var nichen = Ext.getCmp('nichen').getValue();
		var address = Ext.getCmp('address').getValue();
		
		if(name==" "|| password==" " || password2==""){
			Ext.MessageBox.alert('提示','账号或密码不能为空!');
		}
		else if(password != password2){
			Ext.MessageBox.alert('提示','两次密码输入不一致!');
		}else{
		 Ext.Ajax.request({
       url: "<s:url value='/register.action'/>",
       method: 'post',
  		params:{
  			name:name,
  			password:password,
  			username:nichen,
  			address:address
  		},
       success: function (response, options) {
      	Ext.MessageBox.alert('提示','注册成功',function(e){
      		if(e == "ok"){
      			win1.close();
      		} 
      	 });
        
       },
       failure: function (response, options) {
         Ext.MessageBox.alert('注册失败', '请检查您的注册信息!');
       }
     });
		}
	};
	
	land=function(){
		var name = Ext.getCmp('username').getValue(); 
		var password = Ext.getCmp('password').getValue();
		
		
		if(name == " " || password == ""){
			 Ext.MessageBox.alert('提示', '账号或密码不能为空!');
		}
		else{
		 Ext.Ajax.request({
       url: "<s:url value='/login.action'/>",
       method: 'post',
  		params:{
  			name:name,
  			password:password  			
  		},
       success: function (response, options) {
      	Ext.MessageBox.alert('提示','登陆成功!');
        
       },
       failure: function (response, options) {
         Ext.MessageBox.alert('登陆失败', '您输入的账号或密码错误!');
       }
     });
		}
	};
	
</script>
 
</head>
<body>
	
</body>
</html>

大致的步骤就是这样,个人觉得ssi的框架还是蛮不错的,起码定制和自由度都比较好。

精彩图集

赞助商链接