2.26
JavaWeb实现简单的登陆案例demo
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3
4
5
6
7
8
9
10
11 <table align="center"
12 style="background-image: url(); background-repeat: no-repeat"
13 style="楷体" border="1" cellpadding="5" cellspacing="1">
14
15 图书借阅系统登陆入口
16
17 <form action="${pageContext.request.contextPath}/loginservlet"
18 method="post">
19
20 用户名
21
22
23
24
25 密码
26
27
28
29
30
31
32
33
34
35
36
37
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("");
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
4
5
6
7
8
9
10
管理员登陆成功
11 <%
12 String adminid=(String)request.getAttribute("passname");
13 %>
14 欢迎管理员:<%=adminid %>进入系统!
15
功能选项卡:
16 1、进入图书管理
17 2、进入学生管理
18 3、查看借还列表
19
20
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3
4 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5 <%@page import ="enity.NewBook" import="java.util.*"%>
6
7
8
9
10
29
30
31
32
用户登陆成功
33 <%
34 String readerid=(String)request.getAttribute("passname");
35 %>
36 欢迎用户:<%=readerid%>进入系统!
37
38
39
40
41
42
43
44
45
46
47 <c:forEach items="${list}" var="book">
48
49
50
51
52
53
54
57
58 </c:forEach>
59
60 <c:forEach items="${booknamelist}" var="book">
61
62
63
64
65
66
67
70
71 </c:forEach>
72
73 <c:forEach items="${bookauthorlist}" var="book">
74
75
76
77
78
79
80
83
84 </c:forEach>
85
86
| 图书编号 | 图书名称 | 图书作者 | 图书出版社 | 图书可借阅数 | |
|---|---|---|---|---|---|
| ${book.bookid} | ${book.bookname} | ${book.bookauthor} | ${book.pressname} | ${book.availablenum} | 55 借阅 56 |
| ${book.bookid} | ${book.bookname} | ${book.bookauthor} | ${book.pressname} | ${book.availablenum} | 68 借阅 69 |
| ${book.bookid} | ${book.bookname} | ${book.bookauthor} | ${book.pressname} | ${book.availablenum} | 81 借阅 82 |
87
88
89
90
91
92
93
94
95
96
97
98
99
100 <c:forEach items="${borrowlist}" var="book">
101
102
103
104
105
106
107
108
111
114
115 </c:forEach>
116
| 图书编号 | 图书名称 | 图书作者 | 图书出版社 | 图书借阅数 | 图书可借阅天数 | ||
|---|---|---|---|---|---|---|---|
| ${book.bookid} | ${book.bookname} | ${book.bookauthor} | ${book.pressname} | ${book.borrownum} | ${book.availabledate} | 109 借阅 110 | 112 归还 113 |
117
功能选项卡:
118 1、
119 <a
120 href="${pageContext.request.contextPath}/StudentServlet?method=selectAllbooks">查看所有图书列表
121
122 2、
123 <a
124 href="${pageContext.request.contextPath}/StudentServlet?method=selectAllborrowbooks">查看借阅图书列表
125
126
3、查询选项
127
128
129
130
131 <form
132 action="${pageContext.request.contextPath}/StudentServlet?method=findbybookname"
133 method="post" onsubmit='return checkbook()'>
134
135
136
137
138
139
140
141
142
143 <form
144 action="${pageContext.request.contextPath}/StudentServlet?method=findbybookauthor"
145 method="post" onsubmit='return checkauthor()'>
146
147
148
149
150
151
152
153
154
posted on 2025-02-26 23:03 我爱玩原神(原神大王) 阅读(19) 评论(0) 收藏 举报
浙公网安备 33010602011771号