用SSH框架写一个简单的网站登陆系统。
要求1:eclipse平台,SQLServer2005数据库。要求2:有用户注册及登陆功能。要求3:建立一张表,用于存储username、userpwd等简单信息,每次注...
要求1:eclipse平台,SQLServer2005数据库。
要求2:有用户注册及登陆功能。
要求3:建立一张表,用于存储username、userpwd等简单信息,每次注册一个新用户,主键id自动+1。
要求4:体现简单的分层设计思想,如action层、dao层、service层等。
要求5:代码尽量简单,最好不要用log4j.properties,只用ssh、jdbc。
要求6:请于明晚之前给我,如此,加分!
QQ:834133894
邮箱:834133894@qq.com 展开
要求2:有用户注册及登陆功能。
要求3:建立一张表,用于存储username、userpwd等简单信息,每次注册一个新用户,主键id自动+1。
要求4:体现简单的分层设计思想,如action层、dao层、service层等。
要求5:代码尽量简单,最好不要用log4j.properties,只用ssh、jdbc。
要求6:请于明晚之前给我,如此,加分!
QQ:834133894
邮箱:834133894@qq.com 展开
展开全部
我把代码P一下,但是不是按你的关键字,略加修改一下就行:
这个是登录的,注册的就多写一个action就行,......其实就是添加用户,不过得先检验一下是否已经存在这个用户!这里MyHibernateDAO是的自己的一个分页extends自HibernateDAOSupport
表:
create table userinfo(userinfoID int identity(1,1) not null ,
username varchar(10) not null,
password varchar(20) not null,
realname varchar(10)not null,
tel varchar(20),
role varchar(10)not null,
userinfo varchar(5) not null,
PRIMARY KEY(userinfoID ),
);
dao:
package com.last.dao.impl;
import java.util.List;
import com.last.dao.MyHibernateDaoSupport;
import com.last.dao.UserinfoDAO;
import com.last.po.Userinfo;
public class UserinfoDAOImpl extends MyHibernateDaoSupport implements
UserinfoDAO {
@Override
public void save(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().save(userinfo);
}
@Override
public Userinfo findById(Integer userinfoID) throws Exception {
return this.getHibernateTemplate().get(Userinfo.class, userinfoID);
}
@SuppressWarnings("unchecked")
@Override
public Userinfo findByProperty(String propertyName, Object value)
throws Exception {
String hql="from Userinfo as u where u."+propertyName+"=?";
List<Userinfo> userinfo =this.getHibernateTemplate().find(hql, value);
if(userinfo != null && userinfo.size()==1)
{
return userinfo.get(0);
}
return null;
}
@Override
public List<Userinfo> findByPage(Userinfo userinfo, int pageNo)
throws Exception {
return null;
}
@Override
public void update(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().update(userinfo);
}
@Override
public void delete(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().delete(userinfo);
}
@SuppressWarnings("unchecked")
@Override
public List<Userinfo> findAll() throws Exception {
return this.getHibernateTemplate().find("from Userinfo");
}
}
service:
package com.last.service.impl;
import java.util.List;
import com.last.dao.UserinfoDAO;
import com.last.po.Userinfo;
import com.last.service.UserinfoService;
public class UserinfoServiceImpl implements UserinfoService {
private UserinfoDAO userinfoDAO;
public UserinfoDAO getUserinfoDAO() {
return userinfoDAO;
}
public void setUserinfoDAO(UserinfoDAO userinfoDAO) {
this.userinfoDAO = userinfoDAO;
}
@Override
public void saveUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.save(userinfo);
}
@Override
public Userinfo findUserinfoByProperty(String propertyName, Object value)
throws Exception {
return this.userinfoDAO.findByProperty(propertyName, value);
}
@Override
public List<Userinfo> findAllUserinfo() throws Exception {
return this.userinfoDAO.findAll();
}
@Override
public void updateUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.update(userinfo);
}
@Override
public void deleteUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.delete(userinfo);
}
@Override
public boolean login(String username, String password) throws Exception {
System.out.println("进入到service");
System.out.println(username);
System.out.println(password);
if(username==null||"".equals(username))
{
return false;
}else{
Userinfo userinfo = this.userinfoDAO.findByProperty("username", username);
if(!password.equals(userinfo.getPassword()))
{
return false;
}
}
return true;
}
}
action:
package com.last.action;
import java.util.Map;
import com.last.po.Userinfo;
import com.last.service.UserinfoService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Userinfo userinfo;
public Userinfo getUserinfo() {
return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}
private UserinfoService userinfoService;
public UserinfoService getUserinfoService() {
return userinfoService;
}
public void setUserinfoService(UserinfoService userinfoService) {
this.userinfoService = userinfoService;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public String execute() throws Exception {
String username = this.userinfo.getUsername().trim();
String password = this.userinfo.getPassword().trim();
System.out.println("进入到execute");
if(this.userinfoService.login(username, password))
{
Map session = ActionContext.getContext().getSession();
session.clear();
Userinfo userinfo = this.userinfoService.findUserinfoByProperty("username", username);
session.put("userinfo", userinfo);
return SUCCESS;
}
addActionError("用户错误或者密码错误!");
return INPUT;
}
}
这个是登录的,注册的就多写一个action就行,......其实就是添加用户,不过得先检验一下是否已经存在这个用户!这里MyHibernateDAO是的自己的一个分页extends自HibernateDAOSupport
表:
create table userinfo(userinfoID int identity(1,1) not null ,
username varchar(10) not null,
password varchar(20) not null,
realname varchar(10)not null,
tel varchar(20),
role varchar(10)not null,
userinfo varchar(5) not null,
PRIMARY KEY(userinfoID ),
);
dao:
package com.last.dao.impl;
import java.util.List;
import com.last.dao.MyHibernateDaoSupport;
import com.last.dao.UserinfoDAO;
import com.last.po.Userinfo;
public class UserinfoDAOImpl extends MyHibernateDaoSupport implements
UserinfoDAO {
@Override
public void save(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().save(userinfo);
}
@Override
public Userinfo findById(Integer userinfoID) throws Exception {
return this.getHibernateTemplate().get(Userinfo.class, userinfoID);
}
@SuppressWarnings("unchecked")
@Override
public Userinfo findByProperty(String propertyName, Object value)
throws Exception {
String hql="from Userinfo as u where u."+propertyName+"=?";
List<Userinfo> userinfo =this.getHibernateTemplate().find(hql, value);
if(userinfo != null && userinfo.size()==1)
{
return userinfo.get(0);
}
return null;
}
@Override
public List<Userinfo> findByPage(Userinfo userinfo, int pageNo)
throws Exception {
return null;
}
@Override
public void update(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().update(userinfo);
}
@Override
public void delete(Userinfo userinfo) throws Exception {
this.getHibernateTemplate().delete(userinfo);
}
@SuppressWarnings("unchecked")
@Override
public List<Userinfo> findAll() throws Exception {
return this.getHibernateTemplate().find("from Userinfo");
}
}
service:
package com.last.service.impl;
import java.util.List;
import com.last.dao.UserinfoDAO;
import com.last.po.Userinfo;
import com.last.service.UserinfoService;
public class UserinfoServiceImpl implements UserinfoService {
private UserinfoDAO userinfoDAO;
public UserinfoDAO getUserinfoDAO() {
return userinfoDAO;
}
public void setUserinfoDAO(UserinfoDAO userinfoDAO) {
this.userinfoDAO = userinfoDAO;
}
@Override
public void saveUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.save(userinfo);
}
@Override
public Userinfo findUserinfoByProperty(String propertyName, Object value)
throws Exception {
return this.userinfoDAO.findByProperty(propertyName, value);
}
@Override
public List<Userinfo> findAllUserinfo() throws Exception {
return this.userinfoDAO.findAll();
}
@Override
public void updateUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.update(userinfo);
}
@Override
public void deleteUserinfo(Userinfo userinfo) throws Exception {
this.userinfoDAO.delete(userinfo);
}
@Override
public boolean login(String username, String password) throws Exception {
System.out.println("进入到service");
System.out.println(username);
System.out.println(password);
if(username==null||"".equals(username))
{
return false;
}else{
Userinfo userinfo = this.userinfoDAO.findByProperty("username", username);
if(!password.equals(userinfo.getPassword()))
{
return false;
}
}
return true;
}
}
action:
package com.last.action;
import java.util.Map;
import com.last.po.Userinfo;
import com.last.service.UserinfoService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Userinfo userinfo;
public Userinfo getUserinfo() {
return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}
private UserinfoService userinfoService;
public UserinfoService getUserinfoService() {
return userinfoService;
}
public void setUserinfoService(UserinfoService userinfoService) {
this.userinfoService = userinfoService;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public String execute() throws Exception {
String username = this.userinfo.getUsername().trim();
String password = this.userinfo.getPassword().trim();
System.out.println("进入到execute");
if(this.userinfoService.login(username, password))
{
Map session = ActionContext.getContext().getSession();
session.clear();
Userinfo userinfo = this.userinfoService.findUserinfoByProperty("username", username);
session.put("userinfo", userinfo);
return SUCCESS;
}
addActionError("用户错误或者密码错误!");
return INPUT;
}
}
Storm代理
2023-06-05 广告
2023-06-05 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询