先给大家总的说一下这个项目里面用到了哪些功能吧!后面有代码的解析,整个项目的代码已经进行封装了。
首先要说的就是登陆和注册页面,其中用到了前面分享的跳转页面和验证码以及toUpperCase()转换。
以上这张图就是登陆后的主页面,这里面用到了网站中常用的分页查询、session对象(后续还会出一章session与cookie的区别)、绑定数据以及基本的增删改查。
上面这张图可以说是相当于一个增删改查的模板,其中用到了文件上传
这个页面是点击主页面中的新闻主题进来的,也就是说当你对某一条新闻感兴趣的时候,你想了解的更详细的,就可以点击进去,并且可以评论参与该新闻的讨论当中,其中用到了文本编辑器 绑定数据。
这个可以相当于一个游客界面,如果你没登录的话,你可以点击登录注册账号,其中也用到了分页和绑定数据。
以下就是每个页面所对应的代码。
首先我们有四个表,用户表、新闻表、评论表、主题表。每个表都有实体类和方法类(之前出过一章学生管理系统,里面有18个功能,不懂得可以去看看),当你需要用到某个方法的时候就可以直接调用。
登录页面:login.jsp&&dologin.jsp
代码语言:javascript
复制<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录</title>
<link href="../images/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var str = "qwertyupasdfghjkzxcvbnmQWERTYUPASDFGHJKLZXCVBNM23456789";
function yz() {
//随机出4个0-字符串长度之间的数字 做为下标
yzmStr="";
for(var i=1;i<=4;i ){
yzmStr =str.substr(Math.round(Math.random()*(str.length-1)),1);
}
//把验证码赋值到页面
document.getElementById("syzm").innerHTML=yzmStr;
}
function $(id) {
return document.getElementById(id);
}
function login_yz() {
//验证 用户名 和 密码不能为空
//获取用户名
var uname = $("uname").value;
if(uname.length==0){
alert("用户名不能为空");
return false;
}
//获取密码
var upwd = $("upwd").value;
if(upwd.length==0){
alert("密码不能为空");
return false;
}
//获取验证码:判断和电脑的验证码是否相等
//PS:自己实现-输入的验证码不区分大小写-大小写转换
var yzm = $("uyzm").value;
//yzm.lower();
var str1=yzm.toUpperCase();
//alert(str1);
var str2=yzmStr.toUpperCase();
if(str1!=str2){
alert("验证码输入错误,请重新输入");
//清空输入的验证码
$("uyzm").value="";
//重新生成验证码
yz();
return false;
}
}
</script>
</head>
<body>
<body onload="yz()">
<div id="login">
<div id="top">
<div id="top_left">
<img src="../images/login_03.gif" />
</div>
<div id="top_center"></div>
</div>
<div id="center">
<div id="center_left"></div>
<div id="center_middle">
<form action="dologin.jsp" onsubmit="return login_yz()">
<div id="user">
用 户 <input type="text" id="uname" name="textfield" />
</div>
<div id="password">
密 码 <input type="password" id="upwd" name="textfield2" />
</div>
<div id="yzm">
验证码 <input id="uyzm" style="width: 50px;" type="text" name="textfield3" />
<span id="syzm" onclick="yz()"></span>
</div>
<div id="btn">
<input type="submit" value="登录">
<!-- <input type="reset" value="清空"> -->
<input type="button" value="注册" onclick="javascript:location.href='register.jsp'">
</div>
</form>
</div>
<div id="center_right"></div>
</div>
<div id="down">
<div id="down_left">
<div id="inf">
<span class="inf_text">版本信息</span> <span class="copyright">管理信息系统
2008 v2.0</span>
</div>
</div>
<div id="down_center"></div>
</div>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.dao.T277Dao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//乱码
request.setCharacterEncoding("utf-8");
String uname = request.getParameter("textfield");
String jks=request.getParameter("jk");
int jk=0;
String upwd = request.getParameter("textfield2");
T277Dao t=new T277Dao();
T277 T=t.login(uname, upwd);
if(T!=null){//成功就跳转到主页面
session.setAttribute("a", T);
request.getRequestDispatcher("admin.jsp").forward(request, response);
}else{//错误就回到登录页面
out.print("<script>alert('用户名或密码错误,请重新登录');location.href='login.jsp'</script>");
}
%>
注册页面:register.jsp&&doregister.jsp
代码语言:javascript
复制<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户注册</title>
<style>
#a {
width:50%;
height:200px;
border: 1px dashed ;
background-color:lightyellow;
text-align:center;
}
body{
background-color:lightblue;
}
</style>
</head>
<body>
<form action="doregister.jsp" method="post">
用户名:<input type="text" name="uname"><br>
密码:<input type="password" name="upwd"><br>
备注:<textarea rows="" cols="" name="uinfo">
</textarea><br>
<input type="submit" value="注册">
<input type="reset" value="重置">
</form>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.dao.T277Dao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//设置编码-设置请求对象的编号
request.setCharacterEncoding("utf-8");
//接收注册页面传递的数据
String uname = request.getParameter("textfield");
String upwd = request.getParameter("textfield2");
String uinfo = request.getParameter("uinfo");
T277 ss=new T277(uname,upwd,uinfo);
T277Dao df=new T277Dao();
//执行sql语句
int i = df.register(ss);
if(i>0){
out.print("<script>alert('注册成功');location.href='login.jsp'</script>");
}else{
out.print("<script>alert('注册失败');location.href='register.jsp'</script>");
}
%>
主页面:admin.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.News"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.dao.NewsDao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="javascript">
function clickdel(){
return confirm("删除请点击确认");
}
</script>
<form action="admin.jsp" align="center">
<input type="text" name="str">
<input type="submit" value="查询">
</form>
<ul class="classlist">
<%
//获取模糊查询的关键字
String str = request.getParameter("str");
if(str==null){
str = "";
}
int pageIndex = 1;//页码
//接收页码
String index = request.getParameter("pageIndex");
if(index!=null){//如果接收到页面,就给页面pageIndex赋值
pageIndex = Integer.valueOf(index);
}
int pageSize = 5;//每页的数据条数,每页5条数据
//实例化 NewsDao
NewsDao nd = new NewsDao();
int maxPage = nd.getMaxPage(pageSize,str);//调用求 最大页面方法 获取最大页面
//调用分页查询方法
ArrayList<News> nlist = nd.pagelikeNews(pageIndex, pageSize, str);
//遍历集合
for(News n:nlist){
%>
<li>
<a href="read_news.jsp?nid=<%=n.getNid()%>">
<%=n.getNtitle() %>
</a>
<span> 作者:
<%=n.getNzz() %>     
<a href='update_news.jsp?nid=<%=n.getNid()%>'>修改</a>     
<a href='dodel_news.jsp?nid=<%=n.getNid()%>' onclick='return clickdel()'>删除</a> </span> </li>
<li class='space'></li>
<%} %>
<p align="right">
<a href="admin.jsp<%
if(str!=null){
out.print("?str=" str);
}
%>">首页</a> <a href="admin.jsp?pageIndex=<%=pageIndex>1?pageIndex-1:1%><%
if(str!=null){
out.print("&str=" str);
}
%>">上一页</a>
当前页数:[<%=pageIndex %>/<%=maxPage %>]
<a href="admin.jsp?pageIndex=<%=pageIndex<maxPage?pageIndex 1:maxPage%><%
if(str!=null){
out.print("&str=" str);
}
%>">下一页</a>
<a href="admin.jsp?pageIndex=<%=maxPage%><%
if(str!=null){
out.print("&str=" str);
}
%>">末页</a>
</p>
</ul>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
添加新闻:add_news.jsp&&doadd_news.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加新闻--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 添加新闻: </h1>
<form action="doadd_news.jsp" enctype="multipart/form-data" method="post">
<p>
<label> 主题 </label>
<select name="ntid">
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
//2、连接数据库
String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
Connection con = DriverManager.getConnection(url, "scott", "tiger");
//3、定义那个对象,用来执行sql语句
PreparedStatement ps = con.prepareStatement("select * from subject");
ResultSet rs=ps.executeQuery();
while(rs.next()){
%>
<option value="<%=rs.getInt(1)%>"><%=rs.getString(2) %></option>
}
<% }%>
</select>
</p>
<p>
<label> 标题 </label>
<input name="ntitle" type="text" class="opt_input" />
</p>
<p>
<label> 作者 </label>
<input name="nauthor" type="text" class="opt_input" />
</p>
<p>
<label> 摘要 </label>
<textarea name="nsummary" cols="40" rows="3"></textarea>
</p>
<p>
<label> 内容 </label>
<textarea name="ncontent" cols="70" rows="10"></textarea>
</p>
<p>
<label> 上传图片 </label>
<input name="file" type="file" class="opt_input" />
</p>
<input name="action" type="hidden" value="addnews">
<input type="submit" value="提交" class="opt_sub" />
<input type="reset" value="重置" class="opt_sub" />
</form>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.dao.NewsDao"%>
<%@page import="com.zking.entity.News"%>
<%@page import="com.jspsmart.upload.Request"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="com.jspsmart.upload.File"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//创建SmartUpload对象
SmartUpload su = new SmartUpload();
//初始化
su.initialize(pageContext);
//声明一个File对象 用来接收上传的文件
File file = null;
//设置允许上传的文件类型
su.setAllowedFilesList("jpg,png,gif,jpeg");
//设置不允许上传的文件类型
su.setDeniedFilesList("bat,exe,mp4");
//设置单文件大小
su.setMaxFileSize(80000);
//设置总文件大小
su.setTotalMaxFileSize(90000);
//设置编码
su.setCharset("utf-8");
//开始上传
su.upload();
//获取文件集合中的第一个文件
file = su.getFiles().getFile(0);
String filePath = "";
if(!file.isMissing()){
//拼接文件上传到服务器的 路径
filePath ="onload/" file.getFileName();
//上传到服务器 保存到指定路径
file.saveAs(filePath,SmartUpload.SAVE_VIRTUAL);
}
Request req = su.getRequest();
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
//接受添加界面的数据
int tid=Integer.valueOf(req.getParameter("ntid"));
String ntitle=req.getParameter("ntitle");
String nzz=req.getParameter("nauthor");
String nzy=req.getParameter("nsummary");
String nnr=req.getParameter("ncontent");
News x=new News(tid,ntitle,nzz,nzy,nnr,filePath);
NewsDao cs=new NewsDao();
int i=cs.addNews(x);
if(i>0){
out.print("<script>alert('添加成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('添加失败');location.href='add_news.jsp'</script>");
}
%>
添加主题:add_sub.jsp&&doadd_sub.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.T277"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 添加主题: </h1>
<form action="doadd_sub.jsp" method="post">
<p>
<label> 主题: </label>
<input name="nauthor" type="text" class="opt_input" />
</p>
<input name="action" type="hidden" value="addnews">
<input type="submit" value="提交" class="opt_sub" />
<input type="reset" value="重置" class="opt_sub" />
</form>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="com.zking.entity.Subject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//客户端乱码
request.setCharacterEncoding("utf-8");
String nauthor=request.getParameter("nauthor");
Subject sd=new Subject(nauthor);
SubjectDao ff=new SubjectDao();
int i=ff.addsubj(sd);
if(i>0){
out.print("<script>alert('添加成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('添加失败');location.href='add_sub.jsp'</script>");
}
%>
修改新闻:update_news.jsp&&doupdate_news.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.Subject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="com.zking.entity.News"%>
<%@page import="com.zking.dao.NewsDao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改新闻--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 修改新闻: </h1>
<%
int s=Integer.valueOf(request.getParameter("nid"));
NewsDao fd=new NewsDao();
News w=new News();
w=fd.getds(s);
if(w!=null){
%>
<form action="doupdate_news.jsp?nid=<%=request.getParameter("nid")%>&ntid=<%=request.getParameter("ntid") %>" enctype="multipart/form-data" method="post">
<p>
<label> 主题 </label>
<select name="ntid">
<%
SubjectDao ds=new SubjectDao();
ArrayList<Subject> lijkd=ds.getAll();
for(Subject m:lijkd){
%>
<option value="<%=m.getTid()%>"
<%
if(m.getTid()==w.getTid()){
out.print("selected='selected'");
}
%>
>
<%=m.getTname() %></option>
<% }%>
</select>
</p>
<p>
<label> 标题 </label>
<input name="ntitle" type="text" class="opt_input" value="<%=w.getNtitle()%>"/>
</p>
<p>
<label> 作者 </label>
<input name="nauthor" type="text" class="opt_input" value="<%=w.getNzz() %>" />
</p>
<p>
<label> 摘要 </label>
<textarea name="nsummary" cols="40" rows="3">
<%=w.getNzy() %>
</textarea>
</p>
<p>
<label> 内容 </label>
<textarea name="ncontent" cols="70" rows="10"><%=w.getNnr() %>
</textarea>
</p>
<p>
<label> 上传图片 </label>
<input name="file" type="file" class="opt_input" value="<%=w.getNimage()%>"/>
</p>
<input name="action" type="hidden" value="addnews">
<input type="submit" value="修改" class="opt_sub" />
<input type="reset" value="重置" class="opt_sub" />
</form>
<% }%>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.entity.News"%>
<%@page import="com.zking.dao.NewsDao"%>
<%@page import="com.jspsmart.upload.Request"%>
<%@page import="com.jspsmart.upload.File"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//创建SmartUpload对象
SmartUpload su = new SmartUpload();
//初始化
su.initialize(pageContext);
//声明一个File对象 用来接收上传的文件
File file = null;
//设置允许上传的文件类型
su.setAllowedFilesList("jpg,png,gif,jpeg");
//设置不允许上传的文件类型
su.setDeniedFilesList("bat,exe,mp4");
//设置单文件大小
su.setMaxFileSize(800000);
//设置总文件大小
su.setTotalMaxFileSize(9000000);
//设置编码
su.setCharset("utf-8");
//开始上传
su.upload();
//获取文件集合中的第一个文件
file = su.getFiles().getFile(0);
String filePath = "";
if(!file.isMissing()){
//拼接文件上传到服务器的 路径
filePath ="onload/" file.getFileName();
//上传到服务器 保存到指定路径
file.saveAs(filePath,SmartUpload.SAVE_VIRTUAL);
}
Request req = su.getRequest();
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
//接受添加界面的数据
int nid=Integer.valueOf(request.getParameter("nid"));
int tid=Integer.valueOf(req.getParameter("ntid"));
String ntitle=req.getParameter("ntitle");
String nzz=req.getParameter("nauthor");
String nzy=req.getParameter("nsummary");
String nnr=req.getParameter("ncontent");
String nimage=req.getParameter("file");
NewsDao sd=new NewsDao();
News news=new News(tid,ntitle,nzz,nzy,nnr,nimage);
int i=sd.upNews(nid, news);
if(i>0){
out.print("<script>alert('修改成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('修改失败');location.href='update_news.jsp?nid=" nid "'</script>");
}
%>
修改主题:update_sub.jsp&&doupdate_sub.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.Subject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="../login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 修改主题: </h1>
<form action="doupdate_sub.jsp" method="post">
<p>
<label> 主题: </label>
<select name="ntid">
<%
SubjectDao fd=new SubjectDao();
ArrayList<Subject>li=fd.getAll();
for(Subject c:li){
%>
<option value="<%=c.getTid()%>"><%=c.getTname() %></option>
<% }%>
</select>
<input name="nauthor" type="text" class="opt_input" />
</p>
<input name="action" type="hidden" value="addnews">
<input type="submit" value="修改" class="opt_sub" />
<input type="reset" value="重置" class="opt_sub" />
</form>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="com.zking.entity.Subject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
int tid=Integer.valueOf(request.getParameter("ntid"));
String nauthor=request.getParameter("nauthor");
Subject dd=new Subject(nauthor);
SubjectDao df=new SubjectDao();
int i=df.update(dd, tid);
if(i>0){
out.print("<script>alert('修改成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('修改失败');location.href='update_sub.jsp'</script>");
}
%>
删除主题:del_sub.jsp&&dodel_sub.jsp
代码语言:javascript
复制<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.entity.Subject"%>
<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="com.zking.entity.T277"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="welcome">欢迎使用新闻管理系统!</div>
<div id="nav">
<div id="logo"><img src="../images/logo.jpg" alt="新闻中国" /></div>
<div id="a_b01"><img src="../images/a_b01.gif" alt="" /></div>
</div>
</div>
<div id="admin_bar">
<div id="status">管理员: <%=((T277)session.getAttribute("a")).getUname() %>      <a href="login.jsp">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="add_news.jsp">添加新闻</a></li>
<li><a href="admin.jsp">查找新闻</a></li>
<li><a href="add_sub.jsp">添加主题</a></li>
<li><a href="update_sub.jsp">修改主题</a></li>
<li><a href="del_sub.jsp">删除主题</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 删除主题: </h1>
<form action="dodel_sub.jsp" method="post" onsubmit='return clickdel()'>
<script language="javascript">
function clickdel(){
return confirm("删除请点击确认");
}
</script>
<p>
<label> 主题: </label>
<select name="ntid">
<%
SubjectDao sd=new SubjectDao();
ArrayList<Subject> vc=sd.getAll();
for(Subject xz:vc){
%>
<option value="<%=xz.getTid()%>"><%=xz.getTname() %></option>
<%}%>
</select>
</p>
<input name="action" type="hidden" value="addnews">
<input type="submit" value="删除" class="opt_sub" />
<input type="reset" value="重置" class="opt_sub" />
</form>
</div>
</div>
<div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
<div id="footer">
<p class="">24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888<br />
文明办网文明上网举报电话:010-627488888      举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
<p class="copyright">Copyright © 1999-2009 News China gov, All Right Reserver<br />
新闻中国 版权所有</p>
</div>
</body>
</html>
代码语言:javascript
复制<%@page import="com.zking.entity.Subject"%>
<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//乱码
request.setCharacterEncoding("utf-8");
String id=request.getParameter("ntid");
int snid=Integer.valueOf(id);
SubjectDao dd=new SubjectDao();
int i=dd.dele(snid);
if(i>0){
out.print("<script>alert('删除成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('删除失败');location.href='del_sub.jsp'</script>");
}
%>
删除新闻:dodel_news.jsp
代码语言:javascript
复制<%@page import="com.zking.dao.NewsDao"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
//乱码
request.setCharacterEncoding("utf-8");
String id=request.getParameter("nid");
int snid=Integer.valueOf(id);
NewsDao dd=new NewsDao();
int i=dd.delete(snid);
if(i>0){
out.print("<script>alert('删除成功');location.href='admin.jsp'</script>");
}else{
out.print("<script>alert('删除失败');location.href='admin.jsp'</script>");
}
%>
阅读新闻:read_news.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.T277"%>
<%@page import="com.zking.entity.Ptext"%>
<%@page import="com.zking.dao.PtextDao"%>
<%@page import="com.zking.entity.News"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.dao.NewsDao"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="fc" uri="http://java.fckeditor.net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻中国</title>
<link href="../CSS/read.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function clickdel(){
return confirm("删除请点击确认");
}
function check(){
var cauthor = document.getElementById("cauthor");
var content = document.getElementById("ccontent");
if(cauthor.value == ""){
alert("用户名不能为空!!");
return false;
}else if(content.value == ""){
alert("评论内容不能为空!!");
return false;
}
return true;
}
</script>
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<div id="header">
<div id="top_login">
<label> 登录名 </label>
<input type="text" id="uname" value="" class="login_input" />
<label> 密  码 </label>
<input type="password" id="upwd" value="" class="login_input" />
<input type="button" class="login_sub" value="登录" onclick="login()"/>
<label id="error"> </label>
<a href="admin.jsp" class="login_link">返回后台</a> <img src="../images/friend_logo.gif" alt="Google" id="friend_logo" />
<a href="index.jsp" class="login_link">返回首页</a> <img src="../images/friend_logo.gif" alt="Google" id="friend_logo" /> </div>
<div id="nav">
<div id="logo"> <img src="../images/logo.jpg" alt="新闻中国" /> </div>
<div id="a_b01"> <img src="../images/a_b01.gif" alt="" /> </div>
<!--mainnav end-->
</div>
</div>
<div id="container">
<div class="sidebar">
<h1> <img src="../images/title_1.gif" alt="国内新闻" /> </h1>
<div class="side_list">
<ul>
<%
//实例化一个subjectDao对象
NewsDao dds=new NewsDao();
ArrayList<News> wdw=dds.getAll(1);
//遍历集合
for(News n:wdw){
%>
<li> <a href='read_news.jsp?nid=<%=n.getTid()%>'><b><%=n.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
<h1> <img src="../images/title_2.gif" alt="国际新闻" /> </h1>
<div class="side_list">
<ul>
<%
//实例化NewsDao
NewsDao dd=new NewsDao();
ArrayList<News> hh=dd.getAll(2);
for(News v:hh){
%>
<li> <a href='read_news.jsp?nid=<%=v.getNid()%>'><b><%=v.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
<h1> <img src="../images/title_3.gif" alt="娱乐新闻" /> </h1>
<div class="side_list">
<ul>
<%
ArrayList<News> sb=dd.getAll(5);
for(News v:sb){
%>
<li> <a href='read_news.jsp?nid=<%=v.getNid()%>'><b><%=v.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
</div>
<div class="main">
<div class="class_type"> <img src="../images/class_type.gif" alt="新闻中心" /> </div>
<div class="content">
<ul class="classlist">
<%
String id=request.getParameter("nid");
int nid=Integer.valueOf(id);
//3、定义那个对象,用来执行sql语句
NewsDao lk=new NewsDao();
News ddd=lk.getds(nid);
if(ddd!=null){
%>
<table width="80%" align="center">
<tr width="100%">
<td colspan="2" align="center"><%=ddd.getNtitle() %></td>
</tr>
<tr>
<td colspan="2"><hr />
</td>
</tr>
<tr>
<td align="center"><%=ddd.getNdate() %></td>
<td align="left"><%=ddd.getNzz() %> </td>
</tr>
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td colspan="2">
<%=ddd.getNnr() %>
<% }%>
</td>
</tr>
<tr>
<td colspan="2"><hr />
</td>
</tr>
</table>
</ul>
<ul class="classlist">
<%
//查询新闻的评论
PtextDao fds=new PtextDao();
ArrayList<Ptext> sdd=fds.getptex(nid);
for(Ptext v:sdd){
%>
<li>
<%=v.getPnr() %>
<a href="dodelpl.jsp?pid=<%=v.getPid()%>" onclick='return clickdel()'>删除</a>
<a href="#">回复</a>
</li>
<hr>
<%} %>
</ul>
<ul class="classlist">
<form action="doaddpl.jsp" method="post" onsubmit="return check()">
<table width="80%" align="center">
<tr>
<td> 评 论 </td>
</tr>
<tr>
<td> 用户名: </td>
<td><input id="cauthor" name="cauthor" value="<%=((T277)session.getAttribute("a")).getUname()%>"/>
IP:
<input name="cip" value="127.0.0.1" readonly="readonly"/>
</td>
</tr>
<tr>
<td colspan="2"><fc:editor instanceName="str"></fc:editor>
</td>
</tr>
<td><input name="submit" value="发 表" type="submit"/>
</td>
</table>
<input type="hidden" value="<%=nid%>" name="nid">
</form>
</ul>
</div>
</div>
</div>
<div id="friend">
<h1 class="friend_t"> <img src="../images/friend_ico.gif" alt="合作伙伴" /> </h1>
<div class="friend_list">
<ul>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
</ul>
</div>
</div>
<div id="footer">
<p class=""> 24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888 <br />
文明办网文明上网举报电话:010-627488888      举报邮箱: <a href="#">jubao@jb-aptech.com.cn</a> </p>
<p class="copyright"> Copyright © 1999-2009 News China gov, All Right Reserver <br />
新闻中国 版权所有 </p>
</div>
</body>
</html>
添加评论and删除评论:doaddpl.jsp&&dodelpl.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.T277"%>
<%@page import="com.zking.entity.Ptext"%>
<%@page import="com.zking.dao.PtextDao"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
//接收评论人的编号(用户编号)
int uuid = ((T277)session.getAttribute("a")).getUuid();//强转
//评论人的IP
String pip = request.getParameter("cip");
//接收新闻编号(给哪一篇新闻评论)
int nid = Integer.valueOf(request.getParameter("nid"));
session.setAttribute("nid", nid);
//评论内容
String pnr = request.getParameter("str");
//实例化PtextDao对象
PtextDao d=new PtextDao();
//实例化Ptext对象
Ptext ds=new Ptext(uuid,nid,pnr,pip);
//调用添加评论方法
int i = d.addptext(ds);
if(i>0){
out.print("<script>alert('评论成功');location.href='read_news.jsp?nid=" nid "'</script>");
}else{
out.print("<script>alert('评论失败');location.href='read_news.jsp?nid=" nid "'</script>");
}
%>
代码语言:javascript
复制<%@page import="com.zking.dao.PtextDao"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String id=request.getParameter("pid");
Object ids = session.getAttribute("nid");
int nid = (Integer)ids;//强转
int snid=Integer.valueOf(id);
PtextDao fd=new PtextDao();
int i=fd.delte(snid);
if(i>0){
out.print("<script>alert('删除成功');location.href='read_news.jsp?nid=" nid "'</script>");
}else{
out.print("<script>alert('删除失败');location.href='read_news.jsp?nid=" nid "'</script>");
}
%>
游客页面:index.jsp
代码语言:javascript
复制<%@page import="com.zking.entity.News"%>
<%@page import="com.zking.dao.NewsDao"%>
<%@page import="com.zking.entity.Subject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.zking.dao.SubjectDao"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻中国</title>
<link href="../CSS/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function $(id) {
return document.getElementById(id);
}
function login() {
//验证 用户名 和 密码不能为空
//获取用户名
var uname = $("uname").value;
if(uname.length==0){
alert("用户名不能为空");
return false;
}
//获取密码
var upwd = $("upwd").value;
if(upwd.length==0){
alert("密码不能为空");
return false;
}
}
</script>
</head>
<body>
<div id="header">
<div id="top_login">
<form action="login.jsp" onsubmit="return login()">
<label> 登录名 </label>
<input type="text" name="textfield" class="login_input" />
<label> 密  码 </label>
<input type="password" name="textfield2" class="login_input" />
<input type="submit" class="login_sub" value="登录"/>
<input type="hidden" value="1" name="jk">
<label id="error"> </label>
<img src="../images/friend_logo.gif" alt="Google" id="friend_logo" /> </form>
</div>
<div id="nav">
<div id="logo"> <img src="../images/logo.jpg" alt="新闻中国" /> </div>
<div id="a_b01"> <img src="../images/a_b01.gif" alt="" /> </div>
<!--mainnav end-->
</div>
</div>
<div id="container">
<div class="sidebar">
<h1> <img src="../images/title_1.gif" alt="国内新闻" /> </h1>
<div class="side_list">
<ul>
<%
//实例化一个subjectDao对象
NewsDao dds=new NewsDao();
ArrayList<News> slist=dds.getAll(1);
//遍历集合
for(News n:slist){
%>
<li> <a href='read_news.jsp?nid=<%=n.getTid()%>'><b><%=n.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
<h1> <img src="../images/title_2.gif" alt="国际新闻" /> </h1>
<div class="side_list">
<ul>
<%
//实例化NewsDao
NewsDao dd=new NewsDao();
ArrayList<News> hh=dd.getAll(2);
for(News v:hh){
%>
<li> <a href='read_news.jsp?nid=<%=v.getNid()%>'><b><%=v.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
<h1> <img src="../images/title_3.gif" alt="娱乐新闻" /> </h1>
<div class="side_list">
<ul>
<%
ArrayList<News> sb=dd.getAll(5);
for(News v:sb){
%>
<li> <a href='read_news.jsp?nid=<%=v.getNid()%>'><b><%=v.getNtitle() %></b></a> </li>
<%} %>
</ul>
</div>
</div>
<div class="main">
<div class="class_type"> <img src="../images/class_type.gif" alt="新闻中心" /> </div>
<div class="content">
<ul class="class_date">
<li id='class_month'>
<%
SubjectDao sf=new SubjectDao();
ArrayList<Subject> ssa=sf.getAll();
//查询主题
for(Subject vd:ssa){
%>
<a href='index.jsp?tid=<%=vd.getTid() %>'><b> <%=vd.getTname() %> </b></a>
<%} %>
</li>
</ul>
<ul class="classlist">
<%
//实例化NewsDao对象
NewsDao nd=new NewsDao();
//接收页码
String index=request.getParameter("pageIndex");
//接收新闻主题
String id = request.getParameter("tid");
int pageSize = 5;
int maxPage=0;
ArrayList<News> nlist=null;
int pageIndex=1;
if(index!=null){
pageIndex=Integer.valueOf(index);
}
//查询新闻
if(id!=null){//有就根据主题查询
int tid=Integer.valueOf(id);
//调用根据主题查询的最大页码
maxPage=nd.getMaxPagebyid(pageSize, tid);
//调用根据主题查询的数据 分页
nlist=nd.pageNewsbyid(pageIndex, pageSize, tid);
}else{//没有就查询所有
//查询所有的数据最大页码
maxPage=nd.getMaxPage(pageSize, "");
//调用查询所有新闻的方法 分页查询
nlist=nd.pageNews(pageIndex, pageSize);
}
//遍历集合
for(News n:nlist){
%>
<li>
<a href='read_news.jsp?nid=<%=n.getNid()%>'><%=n.getNtitle() %> </a>
<span> <%=n.getNdate() %> </span>
</li>
<li class='space'></li>
<%} %>
<p align="right">
<a href="index.jsp<%
if(id!=null){
out.print("?tid=" id);
}
%>">首页</a>
<a href="index.jsp?pageIndex=<%=pageIndex>1?pageIndex-1:1%><%
if(id!=null){
out.print("&tid=" id);
}
%>">上一页</a>
当前页数:[<%=pageIndex %>/<%=maxPage %>]
<a href="index.jsp?pageIndex=<%=pageIndex<maxPage?pageIndex 1:maxPage%><%
if(id!=null){
out.print("&tid=" id);
}
%>">下一页</a>
<a href="index.jsp?pageIndex=<%=maxPage%><%
if(id!=null){
out.print("&tid=" id);
}
%>">末页</a>
</p>
</ul>
</div>
<div class="picnews">
<ul>
<li> <a href="#"><img src="../images/Picture1.jpg" width="249" alt="" /> </a><a href="#">幻想中穿越时空</a> </li>
<li> <a href="#"><img src="../images/Picture2.jpg" width="249" alt="" /> </a><a href="#">国庆多变的发型</a> </li>
<li> <a href="#"><img src="../images/Picture3.jpg" width="249" alt="" /> </a><a href="#">新技术照亮都市</a> </li>
<li> <a href="#"><img src="../images/Picture4.jpg" width="249" alt="" /> </a><a href="#">群星闪耀红地毯</a> </li>
</ul>
</div>
</div>
</div>
<div id="friend">
<h1 class="friend_t"> <img src="../images/friend_ico.gif" alt="合作伙伴" /> </h1>
<div class="friend_list">
<ul>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
<li> <a href="#">中国政府网</a> </li>
</ul>
</div>
</div>
<div id="footer">
<p class=""> 24小时客户服务热线:010-68988888      <a href="#">常见问题解答</a>      新闻热线:010-627488888 <br />
文明办网文明上网举报电话:010-627488888      举报邮箱: <a href="#">jubao@jb-aptech.com.cn</a> </p>
<p class="copyright"> Copyright © 1999-2009 News China gov, All Right Reserver <br />
新闻中国 版权所有 </p>
</div>
</body>
</html>
其实很多项目里面的功能都是一样的,只要你会用,知道哪些代码放在哪个位置,用一句话来概括前端那就是只要你会copy就行
<( ̄︶ ̄)> *~( ̄▽ ̄)~*
加油吧!程序猿们