目标系统
实验设备管理系统
开发环境
Windows 10
Eclipse 4.7.3
Apache Tomcat 8.0.1
MySQL
开发过程
在环境配置好的情况下开始在eclipse中部署Tomcat和项目
建立数据库和所需的表
编写系统所需jsp与java文件
①登录
//Login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width , initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>实验设备管理系统登录</title>
<style type="text/css" media="screen">
body{
background-color: lightblue;
}
p{
font-size: 15px;
}
#one{
width:500px;
}
#right{
background-color: #20A8D8;
width:410px;
}
#left{
background-color: #1985AC;
}
.btn-link{
font-size: 13px;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<div class="row justify-content-center mt-5">
<div class="col-md-8" align="center">
<div id = "one" class="card-group">
<div class="card p-4">
<form action="LoginServlet" method="post">//设置跳转文件路径
<div class="card-body" align="center">
<h2>实验设备管理系统</h2>
<p class="text-muted">实验人员模式</p>
<div class="input-group mb-3">
<div class="input-group-prepned">
<span class="input-group-text">
<i class="icon-user">实验人员</i>
</span>
</div>
<input class="form-control" type="text" name="username" placeholder="Username">
</div>
<div class="input-group mb-4">
<div class="input-group-prepned">
<span class="input-group-text">
<i class="icon-lock">密 码</i>
</span>
</div>
<input class="form-control" type="password" name="password" placeholder="Password">
</div>
<div class="row" >
<div class="col-6" >
<button type="submit" class="btn btn-primary px-4" id="right" >登录</button> </div>
<br>
<div class="col-7 text-center">
<a href="addID.jsp" style="text-decoration: none;">注册账户</a>
</div>
<div align="right">
<a href="Login_02.jsp" style="text-decoration: none;">切换到管理员</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><!-- jQuery first -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script><!-- then Popper.js -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script><!-- then Bootstrap JS -->
</body>
</html>
//LoginServlet.java
package servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
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.swing.JOptionPane;
import bean.User;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
User user = null ;
//连接数据库
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/equipment";
String username1 = "root";
String password1 = "123456";
Connection conn = DriverManager.getConnection(url,username1,password1);
String sql = "select * from user where username = "+ request.getParameter("username") +" and password = "+request.getParameter("password")+"";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String username = rs.getString("username") ;
String password = rs.getString("password") ;
user = new User(username, password) ;
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
if (user == null ) {
JOptionPane.showMessageDialog(null, "请输入正确的账号和密码", "错误!", JOptionPane.ERROR_MESSAGE);
}else {
request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);
}
}
}
遇到的问题总结
①Tomcat部署项目后,突然关闭的问题:
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre1.8.0_221\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:/jee-oxygen/eclipse/jre/bin/server;D:/jee-oxygen/eclipse/jre/bin;E:\aconda;E:\aconda\Library\mingw-w64\bin;E:\aconda\Library\usr\bin;E:\aconda\Library\bin;
十二月 13, 2019 7:26:44 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:EquipmentManage' did not find a matching property.
下载对应Tomcat版本的tcnative-1.dll并放进Tomcat的bin目录下并重启Tomcat,如果版本不一致,Tomcat会出现提示。
http://archive.apache.org/dist/tomcat/tomcat-connectors/native/