新手求救:用jsp+servlet完成一个用户管理及登陆功能

wulaozi 2010-02-05 08:59:40
对于稍有经验的程序员来说,这是道很简单的题目,可我是新手,但却急用这个程序,还望高手指点!
如果你有意可把源码以附件形式发送给我,最好是Eclipse开发的~


我的邮箱:137488335@qq.com

采用jsp+servlet完成一个用户管理及登陆功能,包括用户的增加、删除、修改 以及登陆验证功能。
用户表结构如下:
Operater:
Operatorid 用户表的id
Userid 登陆用户名
Operatorname 用户名
Password 登陆密码
Email 邮件
Tel 电话

用户增加、修改时 对邮件、电话进行简单的js判断
系统中用户登陆名不能重复
数据库以mysql、sqlserver、oracle 任何一种 ,数据库链接采用连接池方式进行。
...全文
377 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fairy_dy 2010-02-06
  • 打赏
  • 举报
回复
在web.xml里面配置下LoginServlet,下面是LoginServlet的代码

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.szty.hllsys.DBConnectionManage;


public class LoginServlet extends HttpServlet
{
public LoginServlet()
{
super();
}

public void destroy()
{
}

public void init() throws ServletException
{
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html; charset=gb2312");
RequestDispatcher rd;
String pwd = request.getParameter("pwd");
String loginname = request.getParameter("loginname");
loginname = new String(loginname.getBytes("ISO8859-1"), "GBK");

String password = request.getParameter("pwd");

UserBean user = new UserBean();
user.setUsername(loginname);
user.setPassword(password);

HttpSession session = request.getSession(true);

Connection conn = null;
String flag = "0";//0 成功 1 失败
try
{
if (checkUser(conn, loginname, password))
{
session.setAttribute("loginname", loginname);
session.setAttribute("password", password);

rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
flag = "0";
return;
}
else
{
flag = "1";
request.setAttribute("flag", flag);

rd = request.getRequestDispatcher("/default.jsp");
rd.forward(request, response);

}
}
catch (Exception e)
{
e.printStackTrace();
}

}

public boolean checkUser(Connection conn, String username, String password)
throws Exception
{
ResultSet rs = null;
Statement stmt = null;
String sql = "select * from SystemUser where username='" + username
+ "' and password='" + password + "'";
// 获取数据库连接
conn = DBConnectionManage.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);

if (rs.next())
{
UserBean user = new UserBean();

rs.close();
stmt.close();
conn.close();
return true;
}
else
{
conn.close();
return false;
}

}

public int getUserIdByName(String username, String password)
throws Exception
{
ResultSet rs = null;
Statement stmt = null;
Connection conn=null;
String sql = "select userId from SystemUser where username='" + username
+ "' and password='" + password + "'";
// 获取数据库连接
conn = DBConnectionManage.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);


if (rs.next())
{
int userId=Integer.parseInt(rs.getString(1));
rs.close();
stmt.close();
conn.close();

return userId;
}
else
{
rs.close();
stmt.close();
conn.close();
return 0;
}

}

}
wulaozi 2010-02-06
  • 打赏
  • 举报
回复
不是呀
时间比较紧张
一时半会弄不好啊[Quote=引用 12 楼 huxiweng 的回复:]
楼主不要偷懒啊
[/Quote]
zishanyan 2010-02-06
  • 打赏
  • 举报
回复
其他观点上面的各位都说完了,我只能说,这是J2SE板块,LZ的作业时WEB的,你发错版了
acridin 2010-02-06
  • 打赏
  • 举报
回复
CSDN上有很多
http://download.csdn.net/source/1399174
teemai 2010-02-06
  • 打赏
  • 举报
回复
楼主不要偷懒啊
zhuyouyong 2010-02-06
  • 打赏
  • 举报
回复
作业吗
crazylaa 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 inhibitory 的回复:]
如果能把你给的分再乘上一个10, 估计就会有很多人给你做了.
[/Quote]
up
hbhxiaoxue 2010-02-05
  • 打赏
  • 举报
回复
迷糊 作业吧 我也做过 建议自己做吧 要不以后让你改用Struts+Jsp你还是不会啊
jypapgl 2010-02-05
  • 打赏
  • 举报
回复
就是 或者说明下 没分 诚恳点 谁有时间还能给你传个
lianghua19 2010-02-05
  • 打赏
  • 举报
回复
.......25分 给要饭的啊
myj870517 2010-02-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zl3450341 的回复:]
http://www.family168.com/tutorial/jsp/html/
自己跟着学

源码没有
[/Quote]顶,作业要自己做哦.
老张-AI 2010-02-05
  • 打赏
  • 举报
回复
http://www.family168.com/tutorial/jsp/html/
自己跟着学

源码没有
JavaAlpha 2010-02-05
  • 打赏
  • 举报
回复
楼主 可以去 www.bjsxt.com 这里看看 下个视频 里面有源码的
Inhibitory 2010-02-05
  • 打赏
  • 举报
回复
如果能把你给的分再乘上一个10, 估计就会有很多人给你做了.

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧