登陆代码

package com.dao;

import java.util.List;

import com.entity.TblUsers;

public interface UsersDao {

public TblUsers login(String username);

public List<TblUsers> findAllUsers();
}

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

package com.dao.impl;

import java.util.List;

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

import com.dao.UsersDao;
import com.entity.TblUsers;

public class UsersDaoImpl extends HibernateDaoSupport implements UsersDao{

public TblUsers login(String username) {
//获取会话,有session工厂才有session
Session session=this.getSession();
//创建查询,从属性或者类
String hql="from TblUsers where username = ?";//是类型而不是表名
TblUsers user=null;
try {
Query query=session.createQuery(hql);
query.setParameter(0, username);
user = (TblUsers)query.uniqueResult();//用来接收,查数据,返回一个
} catch (Exception e) {
e.printStackTrace();
}finally{
session.close();
}
return user;
}

public List<TblUsers> findAllUsers() {
Session session=this.getSession();
String hql="from TblUsers";
List<TblUsers> ulist=null;
try {
Query query=session.createQuery(hql);
ulist=query.list();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
session.close();
}
return ulist;
}

}

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

package com.service;

import java.util.List;

import com.entity.TblUsers;

public interface UsersService {

TblUsers login(String username);

List<TblUsers> findAllUsers();

}

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

package com.service.impl;

import java.util.List;

import com.dao.UsersDao;
import com.entity.TblUsers;
import com.service.UsersService;

public class UsersServiceImpl implements UsersService{

private UsersDao usersDao;

public UsersDao getUsersDao() {
return usersDao;
}

public void setUsersDao(UsersDao usersDao) {
this.usersDao = usersDao;
}

public TblUsers login(String username){
return usersDao.login(username);
}

public List<TblUsers> findAllUsers() {
return usersDao.findAllUsers();
}

}

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

package com.action;

import java.util.Map;

import com.entity.TblUsers;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UsersService;

public class UsersAction extends ActionSupport{

private UsersService usersService;
private String username;
private String password;
private String errMsg;
private Map<String,Object> session;

public String login(){
TblUsers user=usersService.login(username);
if(user!=null){
//判断密码是否匹配
if(user.getPassword().equals(password)){
session=ActionContext.getContext().getSession();
session.put("userinfo", user);
return SUCCESS;
}else{
this.errMsg="用户名或密码不匹配";
return INPUT;
}

}else{
//用户不存在
this.errMsg="用户不存在";
return INPUT;
}
}

public UsersService getUsersService() {
return usersService;
}
public void setUsersService(UsersService usersService) {
this.usersService = usersService;
}
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 getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public Map<String, Object> getSession() {
return session;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}

}

时间: 2024-10-03 22:40:13

登陆代码的相关文章

asp完整登陆代码

asp完整登陆代码<%option explicit强制浏览器重新访问服务器下载页面,而不是从缓存读取页面Response.Buffer = True Response.Expires = -1Response.ExpiresAbsolute = Now() - 1 Response.Expires = 0 Response.CacheControl = "no-cache" 主要是使随机出现的图片数字随机%><!--#include file="inc/c

python中两段登陆代码的比较

两段登陆代码的比较 第一段 valid_user = 'chuan' valid_passwd = '123' user_input = raw_input("Your username:") passwd = raw_input("Your password:") if user_input == valid_user: if passwd == valid_passwd: print "Welcome %s login to our system!&q

微信网页第三方登陆 代码

1.登陆的html页面代码 <a href="weixin.redirect_uri">微信登陆</a> 2.跳转到的控制器方法代码 CJUL是常量,就是你在开放平台上注册的重定向网址 跳换到后重定向到的地址是微信的一个重定向地址 https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&sco

微信扫码登录asp微信扫码登陆代码

网站接入微信扫码登录并获取用户基本信息(完美绕过微信开放平台) 电脑版网站实现微信扫码登录,注册会员还要设密码太麻烦,会员也记不住密码,采用微信扫码登录网站更方便,会员无需设密码,用他的微信做为系统登录用户名,全程自动操作更方便.源码是用asp写的,mdb的数据库,微信扫描电脑网页上的二维码实现登录. 只需要用微信扫一下二维码,这个网站就可以展示你的微信昵称和头像,免去注册账号和输入密码登录的步骤,还免去设置头像和昵称的步骤,所以是挺方便的.我这个asp写好的代码和微信开放平台不同,微信开放平台

QQ登陆代码

HTML文件中放置QQ登陆按钮 <a href="redirect.asp" target=_self data-role="button" class="ui-btn-right" style="height:24px;line-height:24px;"><img src="Images/bt_blue.png" height="24" alt="QQ登录

Nodejs使用coffeescript编写的用户注册/登陆代码(MySQL)

记录一下,以备后用 Settings = require '../../settings.js' exports.register = (req, res) -> nick_name = req.body.nick_name email = req.body.email password = req.body.password # 配置变量 table_name = 'user_info' database = Settings.mysql.database # 获取当前时间 dateObj =

python实现简单登陆代码

#-*-coding:utf-8 -*- import getpass i1 = raw_input("UserName:") #请输入用户名 i2 = getpass.getpass("PassWord:") print(i1) print(i2)

简单的一个php验证登陆代码

<?php/** */ if ( !isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != 'qiku' || $_SERVER['PHP_AUTH_PW'] != '[email protected]$#@' ) { header('WWW-Authenticate: Basic realm="Login"'); header('HTT

堡垒机 paramiko 自动登陆代码

#!/usr/bin/env python # Copyright (C) 2003-2007 Robey Pointer <[email protected]> # # This file is part of paramiko. # # Paramiko is free software; you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License a