报刊订阅管理系统
又是很久之前写的一期课程设计了 用的软件应该是myeclipse,tomcat,mysql,没有软件的可以私博主,博主有安装包以及教程,对代码有疑问的可以看资源库的压缩包哈。
一、文件夹目录
存放背景图片的文件夹为tupian 存放所有jsp的文件为webroot meta-inf 他是用来配置服务器 加载器以及应用程序的地方 里面的manifrst.mf是配置jar包时自动生成的。
其中conn.jsp 是用来链接mysql数据库的。 Delete.jsp是用来删除期刊功能 Index.jsp是用来设置期刊目录的,链接增删改总功能 Login.jsp是用来做登陆页面的 则login.css是用来修饰login登陆页面的 Manage.jsp是管理员列列表 New.jsp 增加新的报刊 Update.jsp 修改报刊的 User.jsp用户的信息,连接用户的增删改 Useradd.jsp 增加新的用户 Userupdate.jsp修改用户的信息 Usrdelete.jasp 删除用户
二、代码编写过程
Login.jsp的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="login.css">
</head>
<body background = "tupian\333.JPG ">
<form action="#" method="POST">
<div id="login-box">
<h1>Login</h1> <!-- Login的大标题 -->
<div class="form">
<div class="item"> <!-- username部分 -->
<i class="fa fa-user-circle" aria-hidden="true"></i>
<i class="fa fa-key" aria-hidden="true"></i>
<input type="text" placeholder="username" name="username"> <!-- 用文本框实现的username的输入 -->
</div>
<div class="item"> <!-- password部分 -->
<i></i> <!-- 将来用来绘制password前面的图标 -->
<input type="password" placeholder="password" name="password"> <!-- 用password文本框实现的密码输入 -->
</div>
</div>
<a href="index.jsp">
<button type="submit" id ="1">Login</button> <!-- 用button实现的Login登陆按钮 -->
</a>
</div>
</form>
</body>
</html>
Login.css的代码如下
@CHARSET "UTF-8";
#login-box {
border: 1px solid blue;
width: 30%;
text-align: center;
margin: 0 auto;
margin-top: 15%;
background: #00000080;
padding: 20px 50px;
}
#login-box h1 {
color: white;
}
#login-box .form .item input {
width: 200px; /* 设置合适的宽度 */
border: 0; /* 首先将边界取消,方便下面修改下部边界宽度 */
border-bottom: 5px solid white; /* 将下边界进行修改,显示出横线效果 */
font-size: 18px; /* 将字体适当的变大加粗 */
background: #ffffff00; /* 将输入框设置为透明 */
color: black; /* 上面的文本颜色设置为白色,但是placeholder的颜色要单独设置 */
padding: 5px 10px; /* 为了placeholder的内容不是顶格显示,增加内部边界 */
}
#1 {
color:background-image: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
}
#login-box .form .item i {
color: black;
font-size: 18px;
}
Conn.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
<%
//mysql的JDBC驱动程序的类名
String mySqlDriver="com.mysql.jdbc.Driver";
//数据库连接url
String url="jdbc:mysql://localhost:3306/yty";
//数据库连接用的用户名和密码
String user="root";
String pwd="123456";
Connection conn=null;
try{
//加载数据库驱动程序
Class.forName(mySqlDriver).newInstance();
//获取数据库连接
conn=DriverManager.getConnection(url,user,pwd);
}catch(Exception e)
{
out.println("数据库驱动加载出现错误!");
}
%>
Delete.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>删除商品</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<!-- 创建数据库连接 -->
<%@include file="conn.jsp"%>
<%
PreparedStatement stmt=null;
String sql="delete from NewsInfo where NewsID=?";
String NewsID=request.getParameter("NewsID");
stmt = conn.prepareStatement(sql);
stmt.setString(1,NewsID);
try{
if(stmt.executeUpdate()==1)
{
out.println("<script>alert('删除成功!');</script>");
}
else{
out.println("<script>alert('删除失败!');</script>");
}
}
catch(SQLException e){
e.printStackTrace(response.getWriter());
}
%>
<body>
<%
response.sendRedirect("index.jsp");
%>
</body>
<%
stmt.close();
conn.close();
%>
</html>
Index.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>商品首页</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="css/index_style.css">
</head>
<%@include file="conn.jsp"%>
<body background="tupian/yuhui3.png" link="#595959" vlink="#595959">
<%
String sq1="select * from yty.Newsinfo";
PreparedStatement stmt=conn.prepareStatement(sq1);
ResultSet rs=stmt.executeQuery();
%>
<table border="1" cellspacing="0" cellpadding="10" >
<thead>
<tr >
<th class="mycc" colspan="6" >商品列表</th>
</tr>
<tr>
<td align="center">期刊编号</td>
<td align = "center">期刊类别</td>
<td align = "center">期刊名称</td>
<td align="center">出版社</td>
<td align = "center">原价</td>
<td align = "center">操作</td>
</tr>
</thead>
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getString("NewsID") %></td>
<td><%=rs.getString("NewsCno2") %></td>
<td><%=rs.getString("NewsName") %></td>
<td><%=rs.getString("chubanshe") %></td>
<td><%=rs.getString("price") %></td>
<td><a href='update.jsp?NewsID=<%=rs.getString("NewsID") %>'>编辑</a> <a href='delete.jsp?NewsID=<%=rs.getString("NewsID") %>'>删除</a></td>
</tr>
<%} %>
</table>
<br>
<a id="add_style" href="new.jsp">添加期刊</a><br>
<a href="user.jsp"> 用户表</a><br>
<br><br>
<a href="manager.jsp">管理员表</a>
<%
conn.close();
%>
</body>
</html>
Update.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>编辑期刊</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<!-- 创建数据库连接 -->
<%@include file="conn.jsp"%>
<%
//编码改为utf-8
request.setCharacterEncoding("utf-8");
PreparedStatement stmt=null;
String sql="";
String NewsID=request.getParameter("NewsID");
if(request.getMethod().toUpperCase().equals("POST"))
{
String NewsCNo2=request.getParameter("NewsCNo2");
String NewsName=request.getParameter("NewsName");
String chubanshe=request.getParameter("chubanshe");
String price=request.getParameter("price");
sql="update NewsInfo set NewsCNO2=?,NewsName=?,chubanshe=?,price=? where NewsID=?";
stmt = conn.prepareStatement(sql);
stmt.setString(1,NewsCNo2);
stmt.setString(2,NewsName);
stmt.setString(3,chubanshe);
stmt.setDouble(4,Double.valueOf(price));
stmt.setString(5,NewsID);
try{
if(stmt.executeUpdate()==1)
{
out.println("<script>alert('修改成功!');</script>");
}
else{
out.println("<script>alert('修改失败!');</script>");
}
}
catch(SQLException e){
e.printStackTrace(response.getWriter());
}
}
sql="select * from NewsInfo where NewsID=?";
stmt = conn.prepareStatement(sql);
stmt.setString(1,NewsID);
ResultSet rs=stmt.executeQuery();
rs.next();
sql="select * from NewsCategory";
stmt=conn.prepareStatement(sql);
ResultSet rs1=stmt.executeQuery();
%>
<body background="tupian/yuhui.jfif">
<form method="post" action="update.jsp">
<label for="NewsID">期刊编号:</label>
<input type="text" name="NewsID" value='<%=rs.getString("NewsID")%>' readonly><br>
<label for="NewsCNo2">期刊类别:</label>
<select name="NewsCNo2">
<%while(rs1.next()){
if(rs1.getString("NewsCNo").equals(rs.getString("NewsCNo2")))
{
%>
<option value='<%=rs1.getString("NewsCno") %>' selected><%=rs1.getString("NewsCName") %></option>
<%}
else{ %>
<option value='<%=rs1.getString("NewsCno") %>'><%=rs1.getString("NewsCName") %></option>
<%}
} %>
</select><br>
<label for="NewsName">期刊名称:</label>
<input type="text" name="NewsName" value='<%=rs.getString("NewsName")%>'/><br>
<label for="chubanshe">出版报社:</label>
<input type="text" name="chubanshe" value='<%=rs.getString("chubanshe")%>'/><br>
<label for="price">原价:</label>
<input type="text" name="price" value='<%=rs.getString("price")%>'/><br>
<button type="submit">提交</button>
</form>
<br/>
<a href="index.jsp">返回主页</a>
</body>
<%
rs1.close();
rs.close();
stmt.close();
conn.close();
%>
</html>
New.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'new.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="css/new.css">
</head>
<!-- 创建数据库连接 -->
<%@include file="conn.jsp"%>
<%
//编码改为utf-8
request.setCharacterEncoding("utf-8");
PreparedStatement stmt=null;
String sql="";
if(request.getMethod().toUpperCase().equals("POST"))
{
String NewsID=request.getParameter("NewsID");
String NewsCNo2=request.getParameter("NewsCNo2");
String NewsName=request.getParameter("NewsName");
String chubanshe=request.getParameter("chubanshe");
String price=request.getParameter("price");
sql="insert into NewsInfo values(?,?,?,?,?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1,NewsID);
stmt.setString(2,NewsCNo2);
stmt.setString(3,NewsName);
stmt.setString(4,chubanshe);
stmt.setDouble(5,Double.valueOf(price));
try{
if(stmt.executeUpdate()==1)
{
out.println("<script>alert('添加成功!');</script>");
}
else{
out.println("<script>alert('添加失败!');</script>");
}
}
catch(SQLException e){
e.printStackTrace(response.getWriter());
}
}
%>
<%
sql = "select * from NewsCategory";
stmt=conn.prepareStatement(sql);
ResultSet rs=stmt.executeQuery();
%>
<body background="tupian/huaxintwo.jfif">
<form method="post" action="new.jsp" >
<label class="p1" style="display:inline-block;" for="NewsID">期刊编号:</label>
<input type="text" name="NewsID"/><br><br>
<label class="p2" style="display:inline-block;" for="NewsCno2">期刊类别:</label>
<select name="NewsCNo2" id="select">
<%while(rs.next()){
%>
<option value='<%=rs.getString("NewsCno") %>'><%=rs.getString("NewsCName") %></option>
<%} %>
</select><br><br>
<label class="p3" style="display:inline-block;" for="NewsName">期刊名称:</label>
<input type="text" name="NewsName"/><br><br>
<label class="p4" style="display:inline-block;" for="chubanshe">出版报社:</label>
<input type="text" name="chubanshe"/><br><br>
<label class="p5" style="display:inline-block;" for="price">原价:</label>
<input type="text" name="price"/><br><br>
<button class="btn" type="submit">提交</button>
</form>
<a href="index.jsp">返回主页</a>
</body>
<%
rs.close();
stmt.close();
conn.close();
%>
</html>
三、测试截图
1)管理员登录:输入密码和账号进入报刊管理系统 2)进入报刊管理系统,对报刊信息进行增删改,点击用户管理按钮可以进入用户信息管理界面
3)进入添加期刊页面,输入添加的编号,类别,名称,出版社,价格点击提交 4)点击编辑,对已有的报刊信息进行修改 5)点击删除对已有的报刊信息进行删除 6)进入用户管理页面,对用户信息进行增加,修改,删除
四、总结
如果需要整个压缩包的,可以看博主的资源库里,代码里面的图片是要自行修改的,不改会运行不通过哦~ 看完可以点个赞赞再走嘛~~
|