commit
98de7ea0d3
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
|
||||
<servlet>
|
||||
<servlet-name>servletExample</servlet-name>
|
||||
<servlet-class>servlet.ServletExample</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>servletExample</servlet-name>
|
||||
<url-pattern>/servletExample</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<filter-class>filter.CharacterEncodingFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
<filter>
|
||||
<filter-name>AdminFilter</filter-name>
|
||||
<filter-class>filter.AdminFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>AdminFilter</filter-name>
|
||||
<url-pattern>/admin/*</url-pattern>
|
||||
</filter-mapping>
|
||||
<filter>
|
||||
<filter-name>ManagerFilter</filter-name>
|
||||
<filter-class>filter.ManagerFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>ManagerFilter</filter-name>
|
||||
<url-pattern>/manager/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
@ -0,0 +1,12 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>admin title here</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,4 @@
|
||||
driver=com.mysql.jdbc.Driver
|
||||
url=jdbc:mysql://localhost:3306/library?useSSl=true&userUnicode=true&characterEncoding=utf-8
|
||||
username=root
|
||||
password=root
|
@ -0,0 +1,12 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>hello</h1>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>登录页面</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
|
||||
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
|
||||
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="./public/css/animate.css">
|
||||
<link rel="stylesheet" href="./public/css/login.css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="container main">
|
||||
<div id="login" class="contain animated fadeInDown">
|
||||
<h1>用户登录</h1>
|
||||
<form method="post">
|
||||
<input type="text" name="username" class="form-control my_input" placeholder="请输入账号" required="required">
|
||||
<input type="password" name="password" class="form-control my_input" placeholder="请输入密码" required="required">
|
||||
<input type="submit" class="form-control" value="登录" onclick="javascript:void(0);">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="./public/js/layer/layer.js"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
//登录
|
||||
$("input[type=submit]").click(function(){
|
||||
|
||||
$.ajax({
|
||||
url: "./adminLogin",
|
||||
type: "post",
|
||||
data: $("form").serialize(),
|
||||
dataType: "json",
|
||||
success: function( data ){
|
||||
if(data.code == 0){
|
||||
layer.msg("登录成功", {
|
||||
icon: 6,
|
||||
time: 1000
|
||||
}, function(){
|
||||
location.href = data.url;
|
||||
})
|
||||
}else{
|
||||
layer.open({
|
||||
title: "登录失败",
|
||||
content: data.msg,
|
||||
icon: 5,
|
||||
anim: 6
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return false;
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,48 @@
|
||||
body{
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.main{
|
||||
margin-top: 150px;
|
||||
font-family: system-ui,cursive,sans-serif;
|
||||
}
|
||||
#login{
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
padding:25px 45px 45px 45px;
|
||||
box-shadow: 8px 8px #b3e5fc;
|
||||
border-radius: 15px;
|
||||
background-image: -webkit-linear-gradient(top left, #ffd6e7, #cdfcf9);
|
||||
background-image: -o-linear-gradient(top left, #ffd6e7, #cdfcf9);
|
||||
background-image: linear-gradient(to bottom right, #ffd6e7, #cdfcf9);
|
||||
font-size: 16px;
|
||||
}
|
||||
#login h1{
|
||||
color: #4dd0e1;
|
||||
text-align: center;
|
||||
font-size: 30px;
|
||||
}
|
||||
#login .my_input{
|
||||
margin-top: 25px;
|
||||
border: none;
|
||||
background-color: rgba(0,0,0,0);
|
||||
box-shadow: none;
|
||||
border-bottom: 2px solid white;
|
||||
border-radius: 0px;
|
||||
font-size: 20px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
#login .my_input:hover{
|
||||
border-bottom: 2px solid #ff9c6e;
|
||||
|
||||
}
|
||||
#login input[type=submit]{
|
||||
margin-top: 45px;
|
||||
background-color: #fce4ec;
|
||||
font-size: 18px;
|
||||
transition: all 0.5s;
|
||||
border-radius: 15px;
|
||||
}
|
||||
#login input[type=submit]:hover{
|
||||
background-color: #ffd6e7;
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@
|
||||
/*! layer mobile-v2.0.0 Web弹层组件 MIT License http://layer.layui.com/mobile By 贤心 */
|
||||
;!function(e){"use strict";var t=document,n="querySelectorAll",i="getElementsByClassName",a=function(e){return t[n](e)},s={type:0,shade:!0,shadeClose:!0,fixed:!0,anim:"scale"},l={extend:function(e){var t=JSON.parse(JSON.stringify(s));for(var n in e)t[n]=e[n];return t},timer:{},end:{}};l.touch=function(e,t){e.addEventListener("click",function(e){t.call(this,e)},!1)};var r=0,o=["layui-m-layer"],c=function(e){var t=this;t.config=l.extend(e),t.view()};c.prototype.view=function(){var e=this,n=e.config,s=t.createElement("div");e.id=s.id=o[0]+r,s.setAttribute("class",o[0]+" "+o[0]+(n.type||0)),s.setAttribute("index",r);var l=function(){var e="object"==typeof n.title;return n.title?'<h3 style="'+(e?n.title[1]:"")+'">'+(e?n.title[0]:n.title)+"</h3>":""}(),c=function(){"string"==typeof n.btn&&(n.btn=[n.btn]);var e,t=(n.btn||[]).length;return 0!==t&&n.btn?(e='<span yes type="1">'+n.btn[0]+"</span>",2===t&&(e='<span no type="0">'+n.btn[1]+"</span>"+e),'<div class="layui-m-layerbtn">'+e+"</div>"):""}();if(n.fixed||(n.top=n.hasOwnProperty("top")?n.top:100,n.style=n.style||"",n.style+=" top:"+(t.body.scrollTop+n.top)+"px"),2===n.type&&(n.content='<i></i><i class="layui-m-layerload"></i><i></i><p>'+(n.content||"")+"</p>"),n.skin&&(n.anim="up"),"msg"===n.skin&&(n.shade=!1),s.innerHTML=(n.shade?"<div "+("string"==typeof n.shade?'style="'+n.shade+'"':"")+' class="layui-m-layershade"></div>':"")+'<div class="layui-m-layermain" '+(n.fixed?"":'style="position:static;"')+'><div class="layui-m-layersection"><div class="layui-m-layerchild '+(n.skin?"layui-m-layer-"+n.skin+" ":"")+(n.className?n.className:"")+" "+(n.anim?"layui-m-anim-"+n.anim:"")+'" '+(n.style?'style="'+n.style+'"':"")+">"+l+'<div class="layui-m-layercont">'+n.content+"</div>"+c+"</div></div></div>",!n.type||2===n.type){var d=t[i](o[0]+n.type),y=d.length;y>=1&&layer.close(d[0].getAttribute("index"))}document.body.appendChild(s);var u=e.elem=a("#"+e.id)[0];n.success&&n.success(u),e.index=r++,e.action(n,u)},c.prototype.action=function(e,t){var n=this;e.time&&(l.timer[n.index]=setTimeout(function(){layer.close(n.index)},1e3*e.time));var a=function(){var t=this.getAttribute("type");0==t?(e.no&&e.no(),layer.close(n.index)):e.yes?e.yes(n.index):layer.close(n.index)};if(e.btn)for(var s=t[i]("layui-m-layerbtn")[0].children,r=s.length,o=0;o<r;o++)l.touch(s[o],a);if(e.shade&&e.shadeClose){var c=t[i]("layui-m-layershade")[0];l.touch(c,function(){layer.close(n.index,e.end)})}e.end&&(l.end[n.index]=e.end)},e.layer={v:"2.0",index:r,open:function(e){var t=new c(e||{});return t.index},close:function(e){var n=a("#"+o[0]+e)[0];n&&(n.innerHTML="",t.body.removeChild(n),clearTimeout(l.timer[e]),delete l.timer[e],"function"==typeof l.end[e]&&l.end[e](),delete l.end[e])},closeAll:function(){for(var e=t[i](o[0]),n=0,a=e.length;n<a;n++)layer.close(0|e[0].getAttribute("index"))}},"function"==typeof define?define(function(){return layer}):function(){var e=document.scripts,n=e[e.length-1],i=n.src,a=i.substring(0,i.lastIndexOf("/")+1);n.getAttribute("merge")||document.head.appendChild(function(){var e=t.createElement("link");return e.href=a+"need/layer.css?2.0",e.type="text/css",e.rel="styleSheet",e.id="layermcss",e}())}()}(window);
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 701 B |
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
package filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
|
||||
/**
|
||||
* 系统管理员过滤
|
||||
* @author Mingyue
|
||||
*
|
||||
*/
|
||||
public class AdminFilter implements Filter {
|
||||
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
//TODO
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void init(FilterConfig fConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 字符过滤器
|
||||
* @author Mingyue
|
||||
*
|
||||
*/
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CharacterEncodingFilter implements Filter {
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
servletRequest.setCharacterEncoding("UTF-8");
|
||||
servletResponse.setCharacterEncoding("UTF-8");
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
package filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
|
||||
/**
|
||||
* 图书管理员过滤
|
||||
*/
|
||||
public class ManagerFilter implements Filter {
|
||||
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
|
||||
//TODO
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void init(FilterConfig fConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package javabean;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
|
||||
public class Admin {
|
||||
/**
|
||||
* 用户登录
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
* @throws SQLException
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
public String login(String username, String password) throws ClassNotFoundException, SQLException {
|
||||
|
||||
if(username == null || username.trim().equals("")) {
|
||||
return "账号不能为空";
|
||||
}else if(password == null || password.trim().equals("")) {
|
||||
return "密码不能为空";
|
||||
}
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
String sql = "select * from system_manager where username=? and password=? limit 1";
|
||||
connection = Base.getConnection();
|
||||
pstmt = (PreparedStatement) connection.prepareStatement(sql);
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, password);
|
||||
resultSet = pstmt.executeQuery();
|
||||
if(resultSet.next()) {
|
||||
return "1";
|
||||
}
|
||||
return "账号或密码错误";
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package javabean;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
|
||||
public class Base {
|
||||
|
||||
private static String driver = "com.mysql.jdbc.Driver";
|
||||
private static String url = "jdbc:mysql://localhost:3306/library?useSSl=true&userUnicode=true&characterEncoding=utf-8";
|
||||
private static String username = "root";
|
||||
private static String password = "root";
|
||||
|
||||
/**
|
||||
* 获取数据库连接
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static Connection getConnection() throws ClassNotFoundException {
|
||||
Connection connection = null;
|
||||
try{
|
||||
Class.forName(driver);
|
||||
connection = (Connection) DriverManager.getConnection(url, username, password);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共查询
|
||||
* @param connection 连接
|
||||
* @param preparedStatement
|
||||
* @param resultSet 结果集
|
||||
* @param sql
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static ResultSet executequery(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet, String sql, Object[] params) throws SQLException {
|
||||
if(preparedStatement == null){
|
||||
preparedStatement = (PreparedStatement) connection.prepareStatement(sql);
|
||||
}
|
||||
for(int i = 0; params!=null && i < params.length; i++){
|
||||
preparedStatement.setObject(i+1, params[i]);
|
||||
}
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
return resultSet;
|
||||
|
||||
}
|
||||
/**
|
||||
* 公共修改方法
|
||||
* @param connection
|
||||
* @param preparedStatement
|
||||
* @param sql
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static int executeUpdate(Connection connection, PreparedStatement preparedStatement, String sql, Object[] params) throws SQLException {
|
||||
if(preparedStatement == null){
|
||||
preparedStatement = (PreparedStatement) connection.prepareStatement(sql);
|
||||
}
|
||||
for(int i = 0; i < params.length; i++){
|
||||
preparedStatement.setObject(i+1, params[i]);
|
||||
}
|
||||
int updateRows = preparedStatement.executeUpdate();
|
||||
return updateRows;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
* @param connection
|
||||
* @param preparedStatement
|
||||
* @param resultSet
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static boolean closeResource(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) throws SQLException {
|
||||
boolean flag = true;
|
||||
if(resultSet != null){
|
||||
try{
|
||||
resultSet.close();
|
||||
resultSet = null;
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if(preparedStatement != null){
|
||||
try{
|
||||
preparedStatement.close();
|
||||
preparedStatement = null;
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if(connection != null){
|
||||
try{
|
||||
connection.close();
|
||||
connection = null;
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package javabean;
|
||||
|
||||
public class Manager {
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Servlet implementation class ServletExample
|
||||
*/
|
||||
|
||||
public class ServletExample extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ServletExample() {
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package servlet.admin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
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 javabean.Admin;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
* @author Mingyue
|
||||
*
|
||||
*/
|
||||
@WebServlet("/adminLogin")
|
||||
public class AdminLogin extends HttpServlet {
|
||||
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// 设置头文件
|
||||
response.setContentType("application/json; charset=utf8");
|
||||
PrintWriter out = response.getWriter();
|
||||
// 获取账号密码
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
// 设置响应map
|
||||
HashMap<String, Object> hashMap = new HashMap<String, Object>();
|
||||
|
||||
Admin admin = new Admin();
|
||||
String result = null;
|
||||
try {
|
||||
result = admin.login(username, password);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(result.equals("1")) {
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute("admin", username);
|
||||
hashMap.put("code", 0);
|
||||
hashMap.put("msg", "登录成功");
|
||||
hashMap.put("url", request.getContextPath() +"/admin/index");
|
||||
}else {
|
||||
hashMap.put("code", 1);
|
||||
hashMap.put("msg", result);
|
||||
}
|
||||
//response.sendRedirect(request.getContextPath() +"/test.jsp");
|
||||
JSONObject json = JSONObject.fromObject(hashMap);
|
||||
out.write(json.toString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package servlet.manager;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@WebServlet("/managerLogin")
|
||||
public class ManagerLogin extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package test;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
|
||||
import javabean.Base;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||
// Connection connection = Base.getConnection();
|
||||
// String sql = "select * from system_manager";
|
||||
// PreparedStatement pstmt = null;//(PreparedStatement) connect.prepareStatement(sql);
|
||||
//
|
||||
// ResultSet resultSet = null;
|
||||
// resultSet = Base.executequery(connection, pstmt, resultSet, sql, null);
|
||||
// while(resultSet.next()) {
|
||||
// System.out.println(resultSet.getString("username"));
|
||||
// }
|
||||
// Base.closeResource(connection, pstmt, resultSet);
|
||||
// resultSet.close();
|
||||
// System.out.println(resultSet);
|
||||
//System.out.println(resultSet);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue