怎么用servlet、JavaBean、jsp连接数据库做登录界面?
2个回答
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分给你做一个。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询