<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <form name="form1" method="post" action="Copy of do.jsp"> 用户:<input type="text" name="username" id="username" /> <br> 密码:<input type="password" name="password" id="password" /> <br> <input type="submit" value="注册" /> <input type="submit" value="登录" /> </form> </body> </html>
<%@page import="com.ee.dao.UserDao"%> <%@page import="com.ee.bean.User"%> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% User u = new User(); String uname = request.getParameter("name"); u.setUname(uname); String upwd = request.getParameter("password"); u.setUpwd(upwd); UserDao ud=new UserDao(); if(ud.addUser(u)>0){ }else{ } %> <% if(uname.equals("zs")&&upwd.equals("123")){ request.getRequestDispatcher("welcome.jsp").forward(request, response); session.setAttribute("name",name); } else{ request.getRequestDispatcher("login.jsp").forward(request, response); } %>
<%@ page import="com.bean.lty.UserBean" %> <%@ page import="com.dao.lty.Dao" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% UserBean userBean = new UserBean(); String username = request.getParameter("username"); String password = request.getParameter("password"); userBean.setUname(username); userBean.setUpassword(password); Dao dao = new Dao(); int i = dao.UserLogin(userBean); if(i > 0){ HttpSession session1 = request.getSession(); session1.setAttribute("username",username); session1.setAttribute("password",password); request.getRequestDispatcher("success.jsp").forward(request,response); }else{ response.sendRedirect("fail.jsp"); } %> </body> </html>