您的位置:首页 > Web前端 > JavaScript

jsp+jdbc+Servlet实现登录系统(.jsp)

2018-01-11 21:39 489 查看
index.jsp

<%

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>

    This is my JSP page. <br>

    

    <a href="login/login.jsp">登录</a> <br>

    <a href="user/reg.jsp">添加用户</a> <br>

     <a href="QueryAllUserServlet">用户信息的其他管理操作,包括了查询所有,修改、删除</a> <br>

    

  </body>

</html>
login.jsp

<%@ 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 'login.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>

    This is my login JSP page. <br>

    

    <%

    String username =  (String) session.getAttribute("loginUser");

    if (username != null) {

    out.println("当前登录用户:" + username);

    } else {

    out.println("未登录!");

    }

    %>

 

     <form action="LoginUserServlet" method="post" >

    <table align="center">

    <tr>

    <td>Username:</td>

    <td><input type="text" name="username"></td>

    </tr>

    <tr>

    <td>Passwrod:</td>

    <td><input type="password" name="password"></td>

    </tr>

   

    <tr>

    <td> <input type="submit" value="Submit"> </td>

    <td> <input type="reset" value="Reset"> </td>

    </tr>

    </table>

    

    </form>

  </body>

</html>

loginfail.jsp

<%@ 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 'login.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>

    This is my login JSP page. <br>

    

    <%= request.getParameter("username") %> 登录失败!请重新登陆!

    

     <form action="LoginUserServlet" method="post" >

    <table align="center">

    <tr>

    <td>Username:</td>

    <td><input type="text" name="username"></td>

    </tr>

    <tr>

    <td>Passwrod:</td>

    <td><input type="password" name="password"></td>

    </tr>

   

    <tr>

    <td> <input type="submit" value="Submit"> </td>

    <td> <input type="reset" value="Reset"> </td>

    </tr>

    </table>

    

    </form>

  </body>

</html>

loginSucc.jsp

<%@ 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 'loginSucc.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>

    This is my login Succ JSP page. <br>

    

   欢迎  <%= request.getParameter("username") %>     

         

         登录成功! <br>

     <a href="user/reg.jsp">添加用户</a> <br>

     

     <a href="QueryAllUserServlet">用户信息的其他管理操作,包括了查询所有,修改、删除</a> <br>

  </body>

</html>

查询页面listuser.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%

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 'listUser.jsp' starting
c9dc
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">
-->

<script type="text/javascript" >
function del() {
if (confirm("Delete????")) {
return true;
}
return false;

}

</script>

  </head>

  

  <body>

    This is my list JSP page. 55555555 <br>

    

    

    <form action="QuerUserServlet" method="post">

    Username: <input type="text" name="username" />

    Age: > <input type="text" name="minAge" /> < <input type="text" name="maxAge" />

    <input type="submit" value="Query">

    </form>

    

    <table border="2" cellspacing="0" cellpadding="0">

    <tr> 

    <td>NO</td>

    <td>Username</td>

    <td>Pwd</td>

    <td>age</td>

    <td>Update</td>

    <td>Del</td>

    </tr>

   

    <c:forEach items="${requestScope.list}" var="usr" varStatus="status">

    <tr>

    <td>${status.count } </td>

    <td> ${ usr.username } </td>

    <td>${usr.password} </td>

    <td>${usr.age } </td>

    <td><a href="ToUpdateUserServlet?id=${usr.id }">修改</a> </td>

    <td><a href="DeleteUserServlet?id=${usr.id }" onclick="return del();">删除</a> </td>

                

    </tr>
</c:forEach>

   

    </table>

  </body>

</html>

注册页面reg.jsp

<%@ 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 'reg.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>

    This is my reg JSP page. <br>

    

     <form action="RegUserServlet" method="post" >

    <table align="center">

    <tr>

    <td>Username:</td>

    <td><input type="text" name="username"></td>

    </tr>

    <tr>

    <td>Passwrod:</td>

    <td><input type="password" name="password"></td>

    </tr>

   

    <tr>

    <td>Age:</td>

    <td><input type="text" name="age"></td>

    </tr>

   

    <tr>

    <td>Hobs:</td>

    <td>

    <input type="checkbox" name="hobs" value="0" checked="checked"> 篮球

    <input type="checkbox" name="hobs" value="1" > 足球

    <input type="checkbox" name="hobs" value="2" > 排球

    </td>

    </tr>

   

    <tr>

    <td> <input type="submit" value="Submit"> </td>

    <td> <input type="reset" value="Reset"> </td>

    </tr>

    </table>

    

    </form>

    

  </body>

</html>

注册失败refail.jsp

<%@ 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 'regSucc.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>
This is my reg fail JSP page.
<br>

</body>

</html>

注册成功regsucc.jsp

<%@ 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 'regSucc.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>
This is my reg succ JSP page.
<br>

你好 <%= request.getParameter("username") %> ,注册成功!

<br>

<a href="../index.jsp">首页</a>

</body>

</html>

用户信息更新update.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<%

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 'updateUser.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>

    This is my udpate JSP page. <br>

    

     <form action="UpdateUserServlet" method="post" >

     

      <input type="hidden" name="id" value="${usr.id }">

     

    <table align="center">

    <tr>

    <td>Username:</td>

    <td><input type="text" name="username" value="${usr.username }"></td>

    </tr>

   

    <tr>

    <td>Age:</td>

    <td><input type="text" name="age" value="${usr.age }"></td>

    </tr>

   

   

    <tr>

    <td> <input type="submit" value="Update"> </td>

    <td> <input type="reset" value="Reset"> </td>

    </tr>

    </table>

    

    </form>

    

  </body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: