关于分级自测题,我们知道该系统一共分为两个角色,一个是读者,一个是管理员,我们需要根据不同用户去到不同的页面,所以我们需要写一个登陆界面。
本文先写这个功能的实现,该功能主要在servlet里面实现。
一.先写jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"//
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书管理系统:登陆界面</title>
</head>
<body>
<%
Object message = ("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=("message")%>");
</script>
<%} %>
<%
Object message1 = ("message1");//显示注册成功(下一篇博客)
if(message1!=null && !"".equals(message1)){
%>
<script type="text/javascript">
alert("<%=("message1")%>");
</script>
<%} %>
<form action="login_servlet?method=login" method="post">
<table align="center" border="1" >
<tr>
<td>账号: </td>
<td>
<input type="text" name="studentid" />
</td>
</tr>
<tr>
<td>密码: </td>
<td>
<input type="password" name="password"/>
</td>
</tr>
<tr>
<td>身份: </td>
<td>
<select name="form">//这里传值给servlet
<option value="读者"selected>读者</option>
<option value="管理员"selected>管理员</option>
</select>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="登录" />
<a href="" >点击注册</a>
</td>
</tr>
</table>
</body>
</html>
读者功能
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="Bean.*,.*,dao.*,servlet.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="book_servlet?method=looklist" ><h3>浏览图书信息</h3></a>
<a href="" ><h3>查询图书信息</h3></a>
<a href="book_servlet?method=delist" ><h3>借阅图书</h3></a>
<a href="book_servlet?method=borrowlist&borrower=<%=()%>"><h3>浏览催还书目</h3></a>
<a href="book_servlet?method=cuihuan" ><h3>归还图书</h3></a>
</body>
</html>
管理员功能
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="Bean.*,.*,dao.*,servlet.*"%>
<html>
<head>
<meta charset="UTF-8">
<title>管理员界面</title>
</head>
<body>
<a href="" ><h3>添加读者信息</h3></a>
<a href="" ><h3>添加新书信息</h3></a>
<a href="" ><h3>打印催还书信息</h3></a>
</body>
</html>
二.servlet层
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import Bean.xinxi;
import dao.dao;
import daoimpl.daoimpl;
/**
* Servlet implementation class login_servlet
*/
@WebServlet("/login_servlet")
publicclass login_servlet extends HttpServlet {
privatestaticfinallong serialVersionUID = 1L;
dao gooddao=new daoimpl();
/**
* @see HttpServlet#HttpServlet()
*/public login_servlet() {
super();
// TODO Auto-generated constructor stub }
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/protectedvoid doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/protectedvoid doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
("UTF-8");
String method=("method");
String form=("form");//获取来自里面的数据if("login".equals(method)) { //通过判断语句进入不同页面if(("读者"))("").forward(request, response);
elseif(("管理员"))("").forward(request, response);
}
}
三.运行结果
这里只是一个前端页面,没有与数据库打交道,下一篇写验证账号密码是否正确,需要实现注册功能,连接数据库。
喜欢就点点关注吧!!!