码迷,mamicode.com
首页 > 编程语言 > 详细

javaweb登陆实例

时间:2020-12-08 12:13:52      阅读:7      评论:0      收藏:0      [点我收藏+]

标签:generate   orm   order   else   json   EDA   tle   protected   ext   

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>系统入口</title>
 8 </head>
 9 <body>
10     <center>
11         <table align="center"
12             style="background-image: url(); background-repeat: no-repeat"
13             style="楷体" border="1" cellpadding="5" cellspacing="1">
14             <caption>
15                 <font size="3" style="" color="green">图书借阅系统登陆入口</font>
16             </caption>
17             <form action="${pageContext.request.contextPath}/loginservlet"
18                 method="post">
19                 <tr>
20                     <th>用户名</th>
21                     <td align="center"><input type="text" name="passname"><br>
22                     </td>
23                 </tr>
24                 <tr>
25                     <th>密码</th>
26                     <td align="center"><input type="password" name="password"><br>
27                     </td>
28                 </tr>
29                 <td><input type="submit" value="登陆"></td>
30                 <td><input type="reset" value="清除"></td>
31 
32             </form>
33 
34         </table>
35     </center>
36 </body>
37 </html>

servlet

 1 package loginservlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 import repository.LoginRepository;
11 
12 /**
13  * Servlet implementation class loginservlet
14  */
15 @WebServlet("/loginservlet")
16 public class loginservlet extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18     /**
19      * @see HttpServlet#HttpServlet()
20      */
21     public loginservlet() {
22         super();
23         // TODO Auto-generated constructor stub
24     }
25 
26     /**
27      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
28      */
29     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30         // TODO Auto-generated method stub
31         response.getWriter().append("Served at: ").append(request.getContextPath());
32     }
33 
34     /**
35      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
36      */
37     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
38         // TODO Auto-generated method stub
39         request.setCharacterEncoding("utf-8");
40         response.setCharacterEncoding("utf-8");
41         response.setContentType("application/json;charset=utf-8");
42         String passname=request.getParameter("passname");
43         String password=request.getParameter("password");
44         String mark=LoginRepository.checklogin(passname, password);
45         request.setAttribute("passname", passname);
46         request.setAttribute("password", password);
47         if(mark==null) {
48             mark="3";
49             request.getRequestDispatcher("login.jsp").forward(request, response);
50         }
51         if(mark.equals("1")) {
52             String msg="hello world";
53              
54              
55             //method 1:JS Script,缺点:无法转发setAttritute方法中的键值对
56              
57             response.getWriter().write("<script language=javascript>alert(‘" +msg+ "‘);window.location=‘reader_main.jsp‘</script>");
58              
59              
60              
61             request.getRequestDispatcher("reader_main.jsp").forward(request, response);
62         }else if(mark.equals("2")){
63             request.getRequestDispatcher("admin_main.jsp").forward(request, response);
64         }
65         
66     }
67 
68 }

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10     <h1>管理员登陆成功</h1>
11     <%
12         String adminid=(String)request.getAttribute("passname");
13     %>
14     欢迎管理员:<%=adminid %>进入系统!
15     <h1>功能选项卡:</h1>
16     1、<a href="${pageContext.request.contextPath}/bookservlet">进入图书管理</a><br>
17     2、<a href="${pageContext.request.contextPath}/readerservlet">进入学生管理</a><br>
18     3、<a href="${pageContext.request.contextPath }/bookservlet?method=browse">查看借还列表</a>
19 </body>
20 </html>
  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  5 <%@page import ="enity.NewBook" import="java.util.*"%>
  6 <html>
  7 <head>
  8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9 <title>Insert title here</title>
 10      <script type="text/javascript"> 
 11     
 12      function checkbook(){
 13         var f1=document.booknamelist;
 14             if(f1.size()==0){
 15                 alert("根据书名,未查询到结果!");
 16                 return false;
 17             }
 18             return true;
 19     }
 20     function checkauthor(){
 21         var f2=document.bookauthorlist;
 22         if(f2.size()==0){
 23             alert("根据作者名,未查询到结果!");
 24             return false;
 25         }
 26         return true;
 27     } 
 28     </script>
 29 </head>
 30 <body>
 31 
 32     <h1>用户登陆成功</h1>
 33     <%
 34         String readerid=(String)request.getAttribute("passname");
 35     %>
 36     欢迎用户:<%=readerid%>进入系统!<p>
 37     <table align="center" border="1" cellpadding="3" cellspacing="1">
 38         <tr>
 39             <th>图书编号</th>
 40             <th>图书名称</th>
 41             <th>图书作者</th>
 42             <th>图书出版社</th>
 43             <th>图书可借阅数</th>
 44         </tr>
 45         <tr>
 46         </tr>
 47         <c:forEach items="${list}" var="book">
 48             <tr>
 49                 <td align="center">${book.bookid}</td>
 50                 <td align="center">${book.bookname}</td>
 51                 <td align="center">${book.bookauthor}</td>
 52                 <td align="center">${book.pressname}</td>
 53                 <td align="center">${book.availablenum}</td>
 54                 <td>
 55     <a href="${pageContext.request.contextPath}/StudentServlet?borrowmethod=borrowbook&bookid=${book.bookid}&method=selectAllbooks">借阅</a>
 56                 </td>
 57             </tr>
 58         </c:forEach>
 59         
 60         <c:forEach items="${booknamelist}" var="book">
 61             <tr>
 62                 <td align="center">${book.bookid}</td>
 63                 <td align="center">${book.bookname}</td>
 64                 <td align="center">${book.bookauthor}</td>
 65                 <td align="center">${book.pressname}</td>
 66                 <td align="center">${book.availablenum}</td>
 67                 <td>
 68     <a href="${pageContext.request.contextPath}/StudentServlet?borrowmethod=borrowbook&bookid=${book.bookid}&method=selectAllbooks">借阅</a>
 69                 </td>
 70             </tr>
 71         </c:forEach>
 72         
 73         <c:forEach items="${bookauthorlist}" var="book">
 74             <tr>
 75                 <td align="center">${book.bookid}</td>
 76                 <td align="center">${book.bookname}</td>
 77                 <td align="center">${book.bookauthor}</td>
 78                 <td align="center">${book.pressname}</td>
 79                 <td align="center">${book.availablenum}</td>
 80                 <td>
 81     <a href="${pageContext.request.contextPath}/StudentServlet?borrowmethod=borrowbook&bookid=${book.bookid}&method=selectAllbooks">借阅</a>
 82                 </td>
 83             </tr>
 84         </c:forEach>
 85         
 86     </table>
 87     
 88     
 89     
 90     <table align="center" border="1" cellpadding="3" cellspacing="1">
 91         <caption>借阅列表</caption>
 92         <tr>
 93             <th>图书编号</th>
 94             <th>图书名称</th>
 95             <th>图书作者</th>
 96             <th>图书出版社</th>
 97             <th>图书借阅数</th>
 98             <th>图书可借阅天数</th>
 99         </tr>
100             <c:forEach items="${borrowlist}" var="book">
101             <tr>
102                 <td align="center">${book.bookid}</td>
103                 <td align="center">${book.bookname}</td>
104                 <td align="center">${book.bookauthor}</td>
105                 <td align="center">${book.pressname}</td>
106                 <td align="center">${book.borrownum}</td>
107                 <td align="center">${book.availabledate}</td>
108                 <td>
109     <a href="${pageContext.request.contextPath}/StudentServlet?borrowmethod=borrowbook&bookid=${book.bookid}&method=selectAllbooks">借阅</a>
110                 </td>
111                 <td>
112     <a href="${pageContext.request.contextPath}/StudentServlet?givebackmethod=givebackbook&bookid=${book.bookid}&method=selectAllbooks">归还</a>
113                 </td>
114             </tr>
115         </c:forEach>
116         </table>
117     <h1>功能选项卡:</h1>
118     1、
119     <a
120         href="${pageContext.request.contextPath}/StudentServlet?method=selectAllbooks">查看所有图书列表</a>
121     <br>
122     2、
123     <a
124         href="${pageContext.request.contextPath}/StudentServlet?method=selectAllborrowbooks">查看借阅图书列表</a>
125     <br>
126     <br>3、查询选项
127     <br>
128     <br>
129     <table align="left">
130         <caption>①、根据书名查询:</caption>
131         <form
132             action="${pageContext.request.contextPath}/StudentServlet?method=findbybookname"
133             method="post" onsubmit=‘return checkbook()‘>
134             
135             <tr>
136                 <td><input type="text" name="bookname" placeholder="请输入书名"></td>
137             </tr>
138             <td><input type="submit" value="提交" ></td>
139         </form>
140     </table>
141     <table align="left">
142         <caption>②、根据作者查询:</caption>
143         <form
144             action="${pageContext.request.contextPath}/StudentServlet?method=findbybookauthor"
145             method="post"  onsubmit=‘return checkauthor()‘>
146             <tr>
147                 <td><input type="text" name="bookauthor" placeholder="请输入书的作者名"></td>
148             </tr>
149             <td><input type="submit" value="提交" ></td>
150         </form>
151     </table>
152     
153 </body>
154 </html>

 

javaweb登陆实例

标签:generate   orm   order   else   json   EDA   tle   protected   ext   

原文地址:https://www.cnblogs.com/rainbow-1/p/14081450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!