2.13课前练习
1、项目需求:
河北省环保监测中心网络新闻为搭建公众信息交流平台,决定建立新闻发布平台。新闻发布平台按内容包括中心新闻、企业环保信息发布等若干新闻栏目,新闻撰稿人可登陆平台发布新闻,每个新闻栏目至少有一位新闻栏目管理员,负责审查新闻撰稿人所发的新闻稿件,在审查通过后,对应新闻才可以显示在对应新闻栏目上,一般用户登录后才可以看到,另外还可以删除过时或无用的信息。另外,系统管理员可以对用户进行管理和对新闻栏目进行调整。新闻发布流程如下:
2.系统要求与功能设计
2.1 页面要求
(1)通过浏览器查看,能适应常用分辨率;(1分)
(2)布局合理、结构清晰、页面完整;(1分)
(3)网站页面整体风格统一;(1分)
(4)首页为用户登录页面,不同角色用户登录后,进入相应的功能页,要求密码在数据库中加密;(4分)
(5)新闻撰稿人功能页:在线撰写与修改稿件、查看已写稿件及修改意见;
(6)普通用户功能页:浏览相应栏目新闻、用户评论新闻(可匿名)、浏览其他用户评论;
(7)新闻栏目管理员功能页:浏览与管理本栏目待发与已发新闻;
(8)系统管理功能页:用户注册、用户权限管理、新闻栏目管理;
(9)对每页中的查询结果推荐采用分页显示。
2.2 功能要求
(1)在线撰写新闻稿件:新闻撰稿人在线撰写新闻,选择栏目,正式提交;(2分)
(2)查看修改意见:新闻撰稿人查看新闻栏目管理员提出的修改意见;(1分)
(3)修改新闻稿件:新闻撰稿人根据修改意见可以对新闻进行修改;(1分)
(4)查询已经撰写的新闻:新闻撰稿人可以查看自己已经撰写的新闻;(1分)
(5)浏览新闻:普通用户可以浏览栏目的新闻(按照时间倒排);(1分)
图1 新闻发布流程
(6)发表评论回复:普通用户可以对新闻进行发表评论,可选择匿名回复;(1分)
(7)按照一定条件查询新闻:栏目管理员可以按照时间段,新闻关键字等条件进行查询;(2分)
(8)管理待发与已发新闻:新闻栏目管理员可以批准新闻发布、删除不合适新闻、给出撰稿人修改意见、对已发的过时新闻进行删除;(2分)
(9)管理新闻评论回复:新闻栏目管理员可以查看、删除、禁止新闻的回复;(2分)
(10)管理新闻栏目:新开新闻栏目、删除新闻栏目、合并新闻栏目、更改新闻栏目的基本信息;(2分)
(11)用户管理:管理员可以查询用户、批准新用户、暂停用户、为用户赋予角色,普通用户可以修改用户资料。(2分)
2.1,2.2 评分标准:以上各项分值为页面要求和功能要求,各项分值合计(24分);除此以外设计出合理的数据库和数据表(3分),数据库连接正常(2分),设计出用户权限管理(6分)。
2.3 网站发布
(1)网站制作完成后需指定一台机器作为服务器发布。
(2)在其他主机上可正常浏览。
评分标准:能够在Tomcat服务器中正确部署(3分),其它主机可正常浏览(2分);
package 课前23;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import 期末22.Pd;
public class Thesql {
public Connection connect;
public Thesql()throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/keqian23";
String username="root";
String password="2223640185";
connect = DriverManager.getConnection(url,username,password);
}
public void finalize() throws Exception
{
connect.close();
}
public boolean pass(String username,String password,String quanxian) throws Exception
{
String sql="select * from yonghu where username ='"+username+"'";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
String p=rs.getString(3);
String q=rs.getString(4);
if(p.equals(password)&&q.equals(quanxian))
return true;
}
return false;
}
public void addgaojian(String biaoti,String guanjianzi,String zuozhe,String shijian,String zhengwen,String lanmu,String username)throws Exception
{
String sql = "insert into gaojian(biaoti,guanjianzi,zuozhe,shijian,zhengwen,lanmu,username) values(?,?,?,?,?,?,?);";
PreparedStatement pre = connect.prepareStatement(sql);
pre.setString(1,biaoti);
pre.setString(2,guanjianzi);
pre.setString(3,zuozhe);
pre.setString(4,shijian);
pre.setString(5,zhengwen);
pre.setString(6,lanmu);
pre.setString(7,username);
int count=pre.executeUpdate();
pre.close();
}
public String[] showxinwen(String name) throws SQLException
{
String[] arr=new String[20];
int i=0;
String sql="";
if(name==null)
{
sql="select * from gaojian";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
String id=rs.getInt(1)+"";
arr[i]=id;
i++;
}
stmt.close();
return arr;
}
else
{
sql="select * from gaojian where shijian = '"+name+"'";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String na="";
while(rs.next())
{
na=rs.getInt(1)+"";
arr[i]=na;
i++;
}
stmt.close();
return arr;
}
}
public Pd showxinwen1(String tid) throws Exception
{
String sql="select * from gaojian where id ="+tid;
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Pd ppd=new Pd();
while(rs.next())
{
ppd.id=rs.getInt(1);
ppd.biaoti=rs.getString(2);
ppd.guanjianzi=rs.getString(3);
ppd.zuozhe=rs.getString(4);
ppd.shijian=rs.getString(5);
ppd.zhengwen=rs.getString(6);
ppd.lanmu=rs.getString(7);
ppd.username=rs.getString(8);
}
package 课前23;
public class Pd {
public int id;
public String biaoti;
public String guanjianzi;
public String zuozhe;
public String shijian;
public String zhengwen;
public String lanmu;
public String username;
}
package 课前23;
public class Pd2 {
public String gaojian;
public String yijian;
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>新闻发布系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<div>
<h2>新闻发布系统</h2>
<form name="form1" method="get" action="Allstarttj.jsp">
<p>用户名</p ><br>
<input type="text" value="" maxlength="20" name="username"><br><br>
<p>密码</p ><br>
<input type="password" value="" maxlength="20" name="password"><br><br>
<p>选择身份</p ><br>
<select name="shenfen">
<option value="1">新闻撰稿人</option>
<option value="2">普通用户</option>
<option value="3">新闻栏目管理员</option>
<option value="4">系统管理员</option>
</select><br><br>
<button name="tid" value="1" type="submit">登录</button>
</form>
</div>
</body>
</html>
<%@ page import="课前23.Thesql" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>试卷审批管理系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<%
String shenfen="";
String username="";
String password="";
try{shenfen=request.getParameter("shenfen");}
catch(Exception e){}
try{username=request.getParameter("username");}
catch(Exception e){}
try{password=request.getParameter("password");}
catch(Exception e){}
Thesql the = new Thesql();
if(!username.equals(""))
{
if(the.pass(username, password, shenfen))
{
session.setAttribute("uname",username);
session.setAttribute("upwd",password);
if(shenfen.equals("1"))
{
%>
<script type="text/javascript" >
window.location='Start1.jsp' ; //跳转到登录界面
</script>
<%
}
if(shenfen.equals("2"))
{
%>
<script type="text/javascript" >
window.location='Start2.jsp' ; //跳转到登录界面
</script>
<%
}
if(shenfen.equals("3"))
{
%>
<script type="text/javascript" >
window.location='Start3.jsp' ; //跳转到登录界面
</script>
<%
}
if(shenfen.equals("4"))
{
%>
<script type="text/javascript" >
window.location='Start4.jsp' ; //跳转到登录界面
</script>
<%
}
}
else{
%>
<script type="text/javascript" >
alert("登陆失败,用户名或密码错误");
window.location='Allstart.jsp' ; //跳转到登录界面
</script>
<%
}
}
else{
%>
<script type="text/javascript" >
alert("登陆失败,未输入用户名");
window.location='Allstart.jsp' ; //跳转到登录界面
</script>
<%
}
%>
<div>
</div>
</body>
</html>
<%@ page import="课前23.Thesql" %>
<%@ page import="课前23.Pd2" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>结果</title>
<style type="text/css">
div {margin: 100px 400px;}
th {width: 100px;}
</style>
</head>
<body>
<%
String name="";
try{name=request.getParameter("name");}
catch(Exception e) {}
Thesql the = new Thesql();
String[] arr=the.showxinwen(name);
%>
<div>
<form method="get" action="Xiangxi.jsp">
<table border="1" width="500" cellspacing="0">
<caption>结果</caption>
<tr>
<th>稿件</th>
<th>意见</th>
</tr>
<% int i=0;
for(i=1;i<=2;i++)
{
Pd2 pdd=the.showyijian(i+"");
%>
<tr>
<td><% out.print(pdd.gaojian);%></td>
<td><% out.print(pdd.yijian);%></td>
</tr>
<%
} %>
</table>
</form>
<input type="button" onclick="window.location.href='Stustart.jsp';" value="返回主菜单"><br>
</div>
</body>
</html>
<%@ page import="课前23.Thesql" %>
<%@ page import="课前23.Pd" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>结果</title>
<style type="text/css">
div {margin: 100px 400px;}
th {width: 100px;}
</style>
</head>
<body>
<%
String name="";
try{name=request.getParameter("name");}
catch(Exception e) {}
Thesql the = new Thesql();
String[] arr=the.showxinwen(name);
%>
<div>
<form method="get" action="Xiangxi.jsp">
<table border="1" width="500" cellspacing="0">
<caption>结果</caption>
<tr>
<th>标题</th>
<th>关键字</th>
<th>作者</th>
<th>时间</th>
<th>栏目</th>
<th> </th>
</tr>
<% int i=0;
while(arr[i]!=null)
{
Pd pdd=the.showxinwen1(arr[i]);
%>
<tr>
<td><% out.print(pdd.biaoti);%></td>
<td><% out.print(pdd.guanjianzi);%></td>
<td><% out.print(pdd.zuozhe);%></td>
<td><% out.print(pdd.shijian);%></td>
<td><% out.print(pdd.lanmu);%></td>
<td> <button name="tid" value=<%=arr[i]%> type="submit">详细</button></td>
</tr>
<%i++;
} %>
</table>
</form>
<input type="button" onclick="window.location.href='Stustart.jsp';" value="返回主菜单"><br>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>新闻发布系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<div>
<%
String user=(String)session.getAttribute("uname");
%>
<h2>新闻发布系统</h2>
<input type="button" onclick="window.location.href='Liulan.jsp';" value=" 浏览"><br><br>
<input type="button" onclick="window.location.href='Chaxun.jsp';" value="管理"><br><br>
<input type="button" onclick="window.location.href='Allstart.jsp';" value="退出登录"><br><br>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>新闻发布系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<div>
<%
String user=(String)session.getAttribute("uname");
%>
<h2>新闻发布系统</h2>
<input type="button" onclick="window.location.href='Chakanyijian.jsp';" value="用户注册"><br><br>
<input type="button" onclick="window.location.href='Chaxun.jsp';" value="用户权限管理"><br><br>
<input type="button" onclick="window.location.href='Chakan.jsp';" value="栏目管理"><br><br>
<input type="button" onclick="window.location.href='Allstart.jsp';" value="退出登录"><br><br>
</div>
</body>
</html>
<%@ page import="课前23.Pd" %>
<%@ page import="课前23.Thesql" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<%
int tid=-1;
try{
tid=Integer.parseInt(request.getParameter("tid")+"");
}
catch(Exception e) {
e.printStackTrace();
}
Thesql the=new Thesql();
Pd pdd=the.showxinwen1(tid+"");
%>
<div>
<h2>信息</h2>
<p>标题</p><%out.print(" "+pdd.biaoti); %><br>
<p>关键字</p><%out.print(" "+pdd.guanjianzi); %><br>
<p>作者</p><%out.print(" "+pdd.zuozhe); %><br>
<p>时间</p><%out.print(" "+pdd.shijian); %><br>
<p>栏目</p><%out.print(" "+pdd.lanmu); %><br>
<p>正文</p><%out.print(" "+pdd.zhengwen); %><br>
</div>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>新闻发布系统-撰写稿件</title>
<style type="text/css">
div {margin: 0 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
.big{height: 1000px;
width: 500;}
.xh {color: red;}
</style>
</head>
<body>
<h2>新闻发布系统-撰写稿件</h2>
<div class="big">
<form name="form1" method="get" action="Zhuanxietj.jsp">
<p class="xh">*</p>
<p>1.标题</p ><br>
<input type="text" value="" name="biaoti"><br>
<p class="xh">*</p>
<p>2.关键字</p ><br>
<input type="text" value="" name="guanjianzi"><br>
<p class="xh">*</p>
<p>3.作者</p ><br>
<input type="text" value="" name="zuozhe"><br>
<p class="xh">*</p>
<p>4.时间</p ><br>
<input type="text" value="" name="shijian"><br>
<p class="xh">*</p>
<p>5.正文</p ><br>
<input type="text" value="" name="zhengwen"><br>
<p class="xh">*</p>
<p>6.选择新闻栏目</p ><br>
<select name="lanmu">
<option value="民生经济">民生经济</option>
<option value="国家政策">国家政策</option>
<option value="百姓心声">百姓心声</option>
</select><br><br>
<button type="submit">提交</button>
</form>
</div>
</body>
</html>
<%@ page import="课前23.Thesql" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>结果</title>
</head>
<body>
<%
String biaoti="";
String guanjianzi="";
String zuozhe="";
String shijian="";
String zhengwen="";
String lanmu="";
String username=(String)session.getAttribute("uname");
try{biaoti=request.getParameter("biaoti");}
catch(Exception e) {e.printStackTrace();}
try{guanjianzi=request.getParameter("guanjianzi");}
catch(Exception e) {e.printStackTrace();}
try{zuozhe=request.getParameter("zuozhe");}
catch(Exception e) {e.printStackTrace();}
try{shijian=request.getParameter("shijian");}
catch(Exception e) {e.printStackTrace();}
try{zhengwen=request.getParameter("zhengwen");}
catch(Exception e) {e.printStackTrace();}
try{lanmu=request.getParameter("lanmu");}
catch(Exception e) {e.printStackTrace();}
Thesql the = new Thesql();
the.addgaojian(biaoti,guanjianzi,zuozhe,shijian,zhengwen,lanmu,username);
%>
<script type="text/javascript" >
alert("添加成功"); //弹出提示框输出错误信息
window.location='Start1.jsp' ; //跳转到登录界面
</script>
</body>
</html>
pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>新闻发布系统</title> <style type="text/css"> div {margin: 200px 600px;} p {display: inline;} h2 {text-align: center; color: blue;} </style> </head> <body> <div> <% String user=(String)session.getAttribute("uname"); %> <h2>新闻发布系统</h2> <input type="button" onclick="window.location.href='Zhuanxie.jsp';" value="撰写稿件"><br><br> <input type="button" onclick="window.location.href='Chakanyijian.jsp';" value="查看修改意见"><br><br> <input type="button" onclick="window.location.href='Liulan.jsp';" value="按日期查询稿件"><br><br> <input type="button" onclick="window.location.href='Liulan.jsp';" value="查看已写稿件及修改"><br><br> <input type="button" onclick="window.location.href='Allstart.jsp';" value="退出登录"><br><br> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>新闻发布系统</title>
<style type="text/css">
div {margin: 200px 600px;}
p {display: inline;}
h2 {text-align: center;
color: blue;}
</style>
</head>
<body>
<div>
<%
String user=(String)session.getAttribute("uname");
%>
<h2>新闻发布系统</h2>
<input type="button" onclick="window.location.href='Liulan.jsp';" value="浏览新闻"><br><br>
<input type="button" onclick="window.location.href='Chakanyijian.jsp';" value="查看修改意见"><br><br>
<input type="button" onclick="window.location.href='Chaxun.jsp';" value="按日期查询稿件"><br><br>
<input type="button" onclick="window.location.href='Chakan.jsp';" value="查看已写稿件及修改"><br><br>
<input type="button" onclick="window.location.href='Allstart.jsp';" value="退出登录"><br><br>
</div>
</body>
</html>
stmt.close(); return ppd; } public Pd2 showyijian(String tid) throws Exception { String sql="select * from yijian where id ="+tid; Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery(sql); Pd2 ppd=new Pd2(); while(rs.next()) { ppd.gaojian=rs.getString(2); ppd.yijian=rs.getString(3); } stmt.close(); return ppd; } }
浙公网安备 33010602011771号