怎么用servlet、JavaBean、jsp连接数据库做登录界面?

 我来答
匿名用户
2013-09-09
展开全部
jsp部分<form actoin = "" mehtod = "post">username:<input type = "text" name = "username">password:<input type = "password" name = "password"><input type = "submit" value = "OK"></form> javabean部分Userprivate Stirng username;private String password;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;}Dao接口部分public boolean login(String username,String password);Daoimpl Dao接口的实现类public boolean login(String username,Stirng password){Connectoin conn = nullStatement state = null;ResultSet rs = null;boolean flag = false;Class.forName("oracle.jdbc.driver.OracleDriver"");conn = DriverManage.getConnection("jdbc:oracle:thin:l@ocalhost:1521:ora","scott","tiger");state = conn.createStatement();String sql = "select * from users where username = '"+usernmae+"' and password = '"+password+"' ";rs = state.executeQuery(sql);if(rs.next()){flag = true;}return flag;} servlet doPost部分String username = request.getParameter("username");String password= request.getParameter("password");Dao dao = new Daoimpl();boolean flag = dao.login(username,password);if(flag){request.getSession().setAttribute("login","admin");response.sendRedirect("/youProjectName/admin/adminIndex.jsp");}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-09-09
展开全部
jsp和Servlet用一个就能完成,给50分给你做一个。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式