很棒的新聞發(fā)布系統(tǒng)分享給大家,希望大家喜歡。
下面就讓我們來(lái)說(shuō)一說(shuō)基于jsp的新聞發(fā)布系統(tǒng),其中使用的技術(shù)有JavaBean、fillter、數(shù)據(jù)庫(kù)等,能夠?qū)崿F(xiàn)新聞的發(fā)布功能,在發(fā)布之后能夠進(jìn)行對(duì)每一條新聞的刪除、修改、或者繼續(xù)增加新的文章,最后還能夠進(jìn)行查詢功能,其中引用了百度編輯器,能夠進(jìn)行圖文并茂的編輯,極大地方便用戶的使用。
注:完整項(xiàng)目下載地址:新聞發(fā)布系統(tǒng)
一、效果演示
首先讓我們來(lái)看一看實(shí)現(xiàn)的效果:
下面是登陸的首界面:
圖1 首界面
管理員登錄頁(yè)面:
圖2 管理員登錄界面
下面是管理員登陸之后的界面,可以進(jìn)行添加新聞、刪除新聞、查詢新聞:
圖3 管理員管理界面
下面是添加新聞界面,能夠進(jìn)行新聞的添加:
圖4 添加新聞界面
下面是所添加的新聞:
圖5 添加后的新聞
下面是修改新聞界面:
圖6 修改新聞界面下面是修改后的界面
圖7 修改后的界面
下面是刪除新聞后的界面:
圖8 刪除新聞后的界面
對(duì)于新聞的查找,與其他類似,在這里我們使用的是利用新聞編號(hào)進(jìn)行查詢所需的信息,然后在新的頁(yè)面上進(jìn)行顯示。
二、具體實(shí)現(xiàn)過(guò)程
1、環(huán)境:編程環(huán)境為NetBeans8.0和Oracle數(shù)據(jù)庫(kù)
2、數(shù)據(jù)庫(kù)后臺(tái)的設(shè)計(jì)
在新聞管理系統(tǒng)中,我們需要數(shù)據(jù)庫(kù)后臺(tái)管理,其具體步驟如下所示:
根據(jù)所需的業(yè)務(wù)進(jìn)行建表,可參見(jiàn)如下所示:建立數(shù)據(jù)庫(kù)
3、編寫(xiě)步驟:
(1)首先建立以個(gè)項(xiàng)目,在此命名為Demo_08_NewsRealese,項(xiàng)目布局結(jié)構(gòu)如下圖所示,根據(jù)如下布局對(duì)項(xiàng)目進(jìn)行布局設(shè)計(jì),方便后面的編程,項(xiàng)目中web-inf為項(xiàng)目配置文件夾,images文件夾用于儲(chǔ)存項(xiàng)目中使用的圖片文件,ueditor為百度富文本編輯器文件夾,源包文件夾為Java類文件夾:
圖9 項(xiàng)目布局結(jié)構(gòu)圖
接著,我們進(jìn)行創(chuàng)建數(shù)據(jù)庫(kù)連接層,即DAO和VO,分別存于包c(diǎn)om.lut.beans和dao,類命名分別命名為NewsRealese、NewsRealeseDao,對(duì)于類NewsRealese而言,主要是實(shí)現(xiàn)字符串的包裝,其內(nèi)容與數(shù)據(jù)庫(kù)里邊的內(nèi)容一一對(duì)應(yīng),其代碼分別如下所示:
package com.lut.beans;
public class NewsRealese {
private String newsId;
private String classId;
private String kindId;
private String myOther;
private String headTitle;
private String content;
private String connectRealtive;
private String author;
private String editor;
private String newsFrom;
private String top;
private String newsTime;
private String hits;
private String state;
private String tag;
public String getNewsId() {
return newsId;
}
public void setNewsId(String newsId) {
this.newsId = newsId;
}
public String getClassId() {
return classId;
}
public void setClassId(String classId) {
this.classId = classId;
}
public String getKindId() {
return kindId;
}
public void setKindId(String kindId) {
this.kindId = kindId;
}
public String getMyOther() {
return myOther;
}
public void setMyOther(String myOther) {
this.myOther = myOther;
}
public String getHeadTitle() {
return headTitle;
}
public void setHeadTitle(String headTitle) {
this.headTitle = headTitle;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getConnectRealtive() {
return connectRealtive;
}
public void setConnectRealtive(String connectRealtive) {
this.connectRealtive = connectRealtive;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getEditor() {
return editor;
}
public void setEditor(String editor) {
this.editor = editor;
}
public String getNewsFrom() {
return newsFrom;
}
public void setNewsFrom(String newsFrom) {
this.newsFrom = newsFrom;
}
public String getTop() {
return top;
}
public void setTop(String top) {
this.top = top;
}
public String getNewsTime() {
return newsTime;
}
public void setNewsTime(String newsTime) {
this.newsTime = newsTime;
}
public String getHits() {
return hits;
}
public void setHits(String hits) {
this.hits = hits;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
}
下面是類DAO類,命名為NewsRealeseDao.java,對(duì)于DAO類,主要用于實(shí)現(xiàn)數(shù)據(jù)庫(kù)的連接問(wèn)題,進(jìn)行數(shù)據(jù)庫(kù)的鏈接,在連接過(guò)程中需要用到各種有關(guān)數(shù)據(jù)庫(kù)的技術(shù),在這里我們使用的是Oracle數(shù)據(jù)庫(kù),其獲取鏈接的方式為如下代碼,其中第一行為驅(qū)動(dòng)程序名,第二行為數(shù)據(jù)庫(kù)地址(orcl為Oracle數(shù)據(jù)庫(kù)中的SID,在安裝Oracle數(shù)據(jù)庫(kù)時(shí)需要記?。谌袨榫唧w的連接,及使用URL找到數(shù)據(jù)庫(kù)位置,然后使用密碼wjk139登錄到Scott賬戶
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");
其他的操作分別為增刪改查的具體代碼,分別對(duì)應(yīng)Servlet中或jsp中需要實(shí)例化的代碼,下面就是具體的DAO類代碼:
package dao;
import com.lut.beans.NewsRealese;
import static java.lang.System.out;
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 java.util.ArrayList;
public class NewsRealeseDao {
public ArrayList queryAllNews() throws Exception {
Connection conn = null;
ArrayList newsRealese = new ArrayList();
try {
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");
//運(yùn)行SQL語(yǔ)句
String sql = "select * from newmessage";//獲取
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
while (rs.next()) { //實(shí)例化VO
NewsRealese news = new NewsRealese();
news.setNewsId(rs.getString("newsid"));
news.setClassId(rs.getString("CLASSID"));
news.setKindId(rs.getString("KINDID"));
news.setMyOther(rs.getString("MYOTHER"));
news.setHeadTitle(rs.getString("HEADTITLE"));
news.setContent(rs.getString("CONTENT"));
news.setConnectRealtive(rs.getString("CONNECTREALTIVE"));
news.setAuthor(rs.getString("AUTHOR"));
news.setEditor(rs.getString("EDITOR"));
news.setNewsFrom(rs.getString("NEWSFROM"));
news.setTop(rs.getString("TOP"));
news.setNewsTime(rs.getString("NEWSTIME"));
news.setHits(rs.getString("HITS"));
news.setState(rs.getString("STATE"));
news.setTag(rs.getString("TAG"));
newsRealese.add(news);
}
rs.close();
stat.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//關(guān)閉連接
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
return newsRealese;
}
}
//查詢一個(gè)消息
public ArrayList queryOneNews(int newsid) throws Exception {
Connection conn = null;
ArrayList newsRealese = new ArrayList();
int temp_id = newsid;
try {
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");//不安全
//運(yùn)行SQL語(yǔ)句
Statement stat = conn.createStatement();
String sql = "select * from newmessage where newsid=?";//獲取newsid,使用?代替字符串,以免會(huì)發(fā)生錯(cuò)誤
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, Integer.valueOf(newsid));
ResultSet rs = ps.executeQuery();// 之前已經(jīng)給了sql字符串,所以executeUpdate是無(wú)參的。
while (rs.next()) { //實(shí)例化VO
NewsRealese news = new NewsRealese();
news.setNewsId(rs.getString("newsid"));
news.setClassId(rs.getString("CLASSID"));
news.setKindId(rs.getString("KINDID"));
news.setMyOther(rs.getString("MYOTHER"));
news.setHeadTitle(rs.getString("HEADTITLE"));
news.setContent(rs.getString("CONTENT"));
news.setConnectRealtive(rs.getString("CONNECTREALTIVE"));
news.setAuthor(rs.getString("AUTHOR"));
news.setEditor(rs.getString("EDITOR"));
news.setNewsFrom(rs.getString("NEWSFROM"));
news.setTop(rs.getString("TOP"));
news.setNewsTime(rs.getString("NEWSTIME"));
news.setHits(rs.getString("HITS"));
news.setState(rs.getString("STATE"));
news.setTag(rs.getString("TAG"));
newsRealese.add(news);
}
rs.close();
stat.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//關(guān)閉連接
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
return newsRealese;
}
}
//刪除數(shù)據(jù)
public String deleteOneNews(int newsid) throws Exception {
Connection conn = null;
ArrayList newsRealese = new ArrayList();
int temp_id = newsid;
try {
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");//不安全
//運(yùn)行SQL語(yǔ)句
Statement stat = conn.createStatement();
String sql = "DELETE FROM newmessage WHERE newsid =?";//獲取newsid,使用?代替字符串,以免會(huì)發(fā)生錯(cuò)誤
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, Integer.valueOf(newsid));
ResultSet rs = ps.executeQuery();// 之前已經(jīng)給了sql字符串,所以executeUpdate是無(wú)參的。
rs.close();
stat.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//關(guān)閉連接
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
return newsRealese.toString();
}
}
//插入數(shù)據(jù)
public String insertOneNews(ArrayList addnews_list) throws Exception {
Connection conn = null;
/* for(int i=0,j=1;iaddnews_list.size();i++,j++)
{
System.out.println("j:"+j+"值:"+addnews_list.get(i).toString());
}*/
try {
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");//不安全
//運(yùn)行SQL語(yǔ)句
Statement stat = conn.createStatement();
String sql = "insert into newmessage(newsId,classId,kindId,myOther,headTitle,content,connectRealtive,author,editor,newsFrom"
+ ",top,newsTime,hits,state,tag) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";//獲取newsid,使用?代替字符串,以免會(huì)發(fā)生錯(cuò)誤
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, Integer.valueOf(addnews_list.get(0).toString()));
ps.setInt(2, Integer.valueOf(addnews_list.get(1).toString()));
ps.setInt(3, Integer.valueOf(addnews_list.get(2).toString()));
ps.setInt(4, Integer.valueOf(addnews_list.get(3).toString()));
ps.setString(5, addnews_list.get(4).toString());
ps.setString(6, addnews_list.get(5).toString());
ps.setString(7, addnews_list.get(6).toString());
ps.setString(8, addnews_list.get(7).toString());
ps.setString(9, addnews_list.get(8).toString());
ps.setString(10, addnews_list.get(9).toString());
ps.setInt(11, Integer.valueOf(addnews_list.get(10).toString()));
ps.setString(12, addnews_list.get(11).toString());
ps.setString(13, addnews_list.get(12).toString());
ps.setString(14, addnews_list.get(13).toString());
ps.setString(15, addnews_list.get(14).toString());
for (int i = 0, j = 1; i addnews_list.size(); i++, j++) {
System.out.println("j:" + j + "值:" + addnews_list.get(i).toString());
}
int i = ps.executeUpdate();
conn.commit();
System.out.println("成功添加" + i + "行");
stat.close();
conn.close();
return i + "conn:" + conn;
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//關(guān)閉連接
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
}
return conn.toString();
}
//更新數(shù)據(jù)
public String updateOneNews(ArrayList addnews_list) throws Exception {
Connection conn = null;
/* for(int i=0,j=1;iaddnews_list.size();i++,j++)
{
System.out.println("j:"+j+"值:"+addnews_list.get(i).toString());
}*/
try {
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
conn = DriverManager.getConnection(url, "scott", "wjk139");//不安全
//運(yùn)行SQL語(yǔ)句
Statement stat = conn.createStatement();
//獲取newsid,使用?代替字符串,以免會(huì)發(fā)生錯(cuò)誤
String sql = "UPDATE newmessage set classId=?,kindId=?,myOther=?,headTitle=?,content=?,"
+ "connectRealtive=?,author=?,editor=?,newsFrom=?,top=?,newsTime=?,hits=?,state=?,tag=? where newsid=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, Integer.valueOf(addnews_list.get(1).toString()));
ps.setInt(2, Integer.valueOf(addnews_list.get(2).toString()));
ps.setInt(3, Integer.valueOf(addnews_list.get(3).toString()));
ps.setString(4, addnews_list.get(4).toString());
ps.setString(5, addnews_list.get(5).toString());
ps.setString(6, addnews_list.get(6).toString());
ps.setString(7, addnews_list.get(7).toString());
ps.setString(8, addnews_list.get(8).toString());
ps.setString(9, addnews_list.get(9).toString());
ps.setInt(10, Integer.valueOf(addnews_list.get(10).toString()));
ps.setString(11, addnews_list.get(11).toString());
ps.setString(12, addnews_list.get(12).toString());
ps.setString(13, addnews_list.get(13).toString());
ps.setString(14, addnews_list.get(14).toString());
ps.setInt(15, Integer.valueOf(addnews_list.get(0).toString()));
for (int i = 0, j = 1; i addnews_list.size(); i++, j++) {
System.out.println("j:" + j + "值:" + addnews_list.get(i).toString());
}
int i = ps.executeUpdate();
conn.commit();
System.out.println("成功更新" + i + "行");
stat.close();
conn.close();
return i + "conn:" + conn;
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//關(guān)閉連接
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
}
return conn.toString();
}
public String ischecked(String user, String pass) throws Exception {
Connection conn = null;
//獲取連接
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
try {
conn = DriverManager.getConnection(url,user, pass);//不安全
//建立連接
return conn.toString();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
if (conn != null)
{
try {
conn.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
return null;
}
}
(2)首頁(yè)展示頁(yè)面的編寫(xiě),命名為index.html,由于可能有網(wǎng)絡(luò)的延遲,我們使用漸進(jìn)的方式跳轉(zhuǎn)(漸進(jìn)方式跳轉(zhuǎn):window.location.href="newRealese_brief.jsp",從index.html頁(yè)面跳轉(zhuǎn)到ewRealese_brief.jsp頁(yè)面),代碼如下所示:
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
title>新聞發(fā)布系統(tǒng)--最前沿的時(shí)尚信息、最有看點(diǎn)的社會(huì)聚焦、最富得浪漫的殿堂/title>
/head>
body id="body">
正在跳轉(zhuǎn)...,請(qǐng)等待...
script language="javascript" type="text/javascript">
window.location.href="newRealese_brief.jsp";
/script>
/body>
/html>
在緩沖時(shí),會(huì)進(jìn)行跳轉(zhuǎn),跳轉(zhuǎn)后的頁(yè)面為newRealese_brief.jsp,其代碼如下所示:進(jìn)入新聞?wù)故卷?yè)面之后,我們能夠?qū)π侣勥M(jìn)行搜素,還能夠查看詳細(xì)內(nèi)容。
%@page contentType="text/html" import="java.util.*,java.sql.*,com.lut.beans.NewsRealese,dao.NewsRealeseDao"
pageEncoding="UTF-8" language="java"%>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>新聞發(fā)布系統(tǒng)--最前沿的時(shí)尚信息、最有看點(diǎn)的社會(huì)聚焦、最富得浪漫的殿堂/title>
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
/head>
body id="body">
a href="adminLogin.jsp" style="table-layout: right">管理員登錄/a>h1 id="p">最新資訊/h1>br>
%@include file="a_queryNews.jsp" %>
table border="0" style="width:100%; height:100%" align="center">
tr>
td style="width: 10%">nbsp;/td>
td>
%
NewsRealeseDao newsRealeseDao = new NewsRealeseDao();
ArrayList newsRealese = newsRealeseDao.queryAllNews();
%>
%
for (int i = 0; i newsRealese.size(); i++) {
NewsRealese newRealese = (NewsRealese) newsRealese.get(i);
%>
center>table border="0" width="100%" id="table">
tr>
td width="128">p>此處假設(shè)無(wú)圖片/p>
p>此處假設(shè)無(wú)等級(jí)信息/p>
/td>
td >table border="0" width="100%">
tr>
td width="11%" >原創(chuàng)或轉(zhuǎn)載:/td>
td colspan="3">%=newRealese.getMyOther()%> /td>
td width="10%" >新聞標(biāo)題:/td>
td width="44%" >%=newRealese.getHeadTitle()%> /td>
/tr>
tr>
td colspan="6">新聞內(nèi)容:/td>
/table>
table width="100%" border="0">
tr>
td>
a target="_blank" href="newRealese_detail.jsp?newsid=%=newRealese.getNewsId()%>"/>
table width="100%" border="0" align="center">
tr>
td>
%=newRealese.getContent()%>
/td>
/tr>
/table>
/td>
/tr>
/table>
table border="0" width="100%">
tr>
td width="51" height="30">作者:/td>
td width="203">%=newRealese.getAuthor()%> /td>
td width="97">新聞發(fā)布時(shí)間:/td>
td width="167">%=newRealese.getNewsTime()%> /td>
td width="99">新聞點(diǎn)擊次數(shù):/td>
td width="191">%=newRealese.getHits()%> /td>
/tr>
/table>/td>
/tr>
tr>
td height="21" colspan="2">hr>/td>
/tr>
/table>/center>
%
}
%>
/td>
td>nbsp;/td>
/tr>
tr>
td>nbsp;/td>
td>nbsp;/td>
td>nbsp;/td>
/tr>
/table>
/body>
/html>
(3)詳細(xì)新聞頁(yè)面的設(shè)計(jì),命名為newRealese_detail.jsp其代碼如下所示:再詳細(xì)新聞頁(yè)面上,我們能夠進(jìn)行數(shù)據(jù)的詳細(xì)情況的了解,在觀看完詳細(xì)信息之后,我們能夠進(jìn)行點(diǎn)擊返回按鈕進(jìn)行返回操作
%@page contentType="text/html" import="java.util.*,java.sql.*" pageEncoding="UTF-8" language="java"%>
%@page import="com.lut.beans.NewsRealese" %>
%@page import="dao.NewsRealeseDao" %>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
title>新聞發(fā)布系統(tǒng)--最前沿的時(shí)尚信息、最有看點(diǎn)的社會(huì)聚焦、最值得浪漫的殿堂/title>
/head>
body id="body">
h1>最新資訊/h1>br>
%
String newsid=request.getParameter("newsid");
int newsid_int=Integer.parseInt(newsid);
NewsRealeseDao newsRealeseDao=new NewsRealeseDao();
ArrayList newsRealese=newsRealeseDao.queryOneNews(newsid_int);
%>
table border="1">
tr >
td >新聞編號(hào)/td>
td>所屬新聞欄目編號(hào)/td>
td>所屬新聞分類編號(hào)/td>
td>原創(chuàng)或轉(zhuǎn)載/td>
td>新聞標(biāo)題/td>
td>新聞內(nèi)容/td>
td>相關(guān)文章/td>
td>作者/td>
td>編輯/td>
td>出處/td>
td>是否置頂/td>
td>新聞發(fā)布時(shí)間/td>
td>新聞點(diǎn)擊次數(shù)/td>
td>新聞狀態(tài)/td>
td>新聞標(biāo)記/td>
/tr>
%
for(int i=0;inewsRealese.size();i++)
{
NewsRealese newRealese=(NewsRealese)newsRealese.get(i);
%>
tr>
td>%=newRealese.getNewsId() %> /td>
td>%=newRealese.getClassId() %> /td>
td>%=newRealese.getKindId() %> /td>
td>%=newRealese.getMyOther() %> /td>
td>%=newRealese.getHeadTitle()%> /td>
td>%=newRealese.getContent() %> /td>
td>%=newRealese.getConnectRealtive()%>/td>
td>%=newRealese.getAuthor() %> /td>
td>%=newRealese.getEditor() %> /td>
td>%=newRealese.getNewsFrom() %> /td>
td>%=newRealese.getTop() %> /td>
td>%=newRealese.getNewsTime() %> /td>
td>%=newRealese.getHits() %> /td>
td>%=newRealese.getState() %> /td>
td>%=newRealese.getTag() %> /td>
/tr>
/table>
table width="100%" border="0" cellspacing="0" cellpadding="4">
tr>
td width="100%" style="text-align: center; vertical-align: top">
table width="90%" border="0" cellpadding="0" cellspacing="0">
tr>
td>
table width="100%" border="0" cellspacing="1" cellpadding="4" >
tr>
th width="26%" class="TitleColor" style="text-align: right; vertical-align: top" scope="row">新聞標(biāo)題: /th>
td width="74%" style="vertical-align: top" class="TitleColor" >p align="left">%=newRealese.getHeadTitle()%>p>/td>
/tr>
tr>
th scope="row" class="TitleColor" style="text-align: right; vertical-align: top">作者:/th>
td style="vertical-align: top">p align="left">%=newRealese.getAuthor() %> p> /td>
/tr>
tr>
th scope="row" class="TitleColor" style="text-align: right; vertical-align: top">新聞發(fā)布時(shí)間: /th>
td style="vertical-align: top" class="TitleColor">p align="left">%=newRealese.getNewsTime() %>p>/td>
/tr>
tr>
th scope="row" class="TitleColor" style="text-align: right; vertical-align: top">新聞點(diǎn)擊次數(shù): /th>
td style="vertical-align: top" class="TitleColor">p align="left">%=newRealese.getHits() %>p>/td>
/tr>
tr>
td colspan="2" class="StoryContentColor">p align="center">%=newRealese.getContent() %>p>/td>
/tr>
/table>
/td>
/tr>
/table>
p>nbsp;/p>
table>
tr>
td >
a href="newRealese_brief.jsp">返回/a>
/td>
td>
a href="#">發(fā)表評(píng)論/a>
/td>
/tr>
/table>
/td>
/tr>
/table>
table width="100%" border="0" cellspacing="0" cellpadding="4">
tr style="text-align: right">
td> a href="#">點(diǎn)贊/a> a href="#">舉報(bào)/a> a href="#">投稿,聯(lián)系作者/a>nbsp; /td>
/tr>
/table>
%
}
%>
/body>
/html>
(4)管理員登錄界面,命名為adminLogin.jsp頁(yè)面,使用連接數(shù)據(jù)庫(kù)的方式進(jìn)行登錄,在這里我們的管理員名稱為Scott,密碼為wjk139,管理員登錄界面的實(shí)現(xiàn)代碼如下所示
%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
title>新聞發(fā)布系統(tǒng)--最前沿的時(shí)尚信息、最有看點(diǎn)的社會(huì)聚焦、最值得浪漫的殿堂/title>
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
/head>
body id="body">
form method="post" action="checkLogin">
table border="0" align="center" id="table_vertical" >
caption>管理員登錄 /caption>
tr>
td width="40">Admin/td>
td width="183">
input type="text" name="user">/td>
/tr>
tr>
td height="25">Pass/td>
td>input type="password" name="pass">/td>
/tr>
/table>
table align="center">
tr>
td>
input type="submit" value="Login">
input type="reset" value="Reset">
/td>
/tr>
/table>
/form>
/body>
/html>
在登錄的過(guò)程中,我們需要進(jìn)行判斷,命名為checkLogin.java,,通過(guò)此類進(jìn)行判斷登錄是否成功,若成功,則跳轉(zhuǎn)到管理界面,若失敗,則停留在當(dāng)前界面,其代碼如下所示:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import com.lut.beans.NewsRealese;
import dao.NewsRealeseDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class checkLogin extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String user=request.getParameter("user");
String pass=request.getParameter("pass");
NewsRealeseDao newsRealeseDao=new NewsRealeseDao();
try {
String newsRealese=newsRealeseDao.ischecked(user,pass);
if(newsRealese!=null)
{
response.sendRedirect("adminManager.jsp");
}
else
{
response.sendRedirect("adminLogin.jsp");
}
}
catch (Exception ex)
{
Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description"+"public String getServletInfo() ";
}// /editor-fold>
}
(5)管理員登陸之后的界面,命名為adminManager.jsp頁(yè)面,在管理員界面能夠進(jìn)行刪除修改增加和查詢操作,其代碼如下所示:
%--
Document : adminManager
Created on : 2016-5-18, 17:10:01
Author : Administrator
--%>
%@page import="java.util.ArrayList"%>
%@page import="com.lut.beans.NewsRealese"%>
%@page import="dao.NewsRealeseDao"%>
%@page contentType="text/html" pageEncoding="UTF-8"%>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>管理員界面||adminManager.jsp/title>
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
/head>
body id="body" style=" text-orientation: vertical-right">
h1 id="p">新聞管理/h1>br>
table border="1" style="width:100%; height:100%">
tr>
td width="10%" style="text-align:top">
table border="0" style="width: 100%;height: 100%" >
tr>
td>div align="center">新聞信息顯示 /div>/td>
/tr>
tr>
td>img src="./images/dog.jpg" width="100%" height="90%">/td>
/tr>
tr>
td>img src="./images/minus.gif" >/td>
/tr>
/table>/td>
td width="50%">
table border="0">
tr>
td>
% NewsRealeseDao newsRealeseDao = new NewsRealeseDao();
ArrayList newsRealese = newsRealeseDao.queryAllNews();
%>
%
for (int i = 0; i newsRealese.size(); i++) {
NewsRealese newRealese = (NewsRealese) newsRealese.get(i);
%>
table border="0" width="100%" id="table">
tr>
td width="128">p>此處假設(shè)無(wú)圖片/p>
p>此處假設(shè)無(wú)等級(jí)信息/p> /td>
td >table border="0" width="100%">
tr>
td >原創(chuàng)或轉(zhuǎn)載:/td>
td >%=newRealese.getMyOther()%> /td>
td >新聞標(biāo)題:/td>
td >%=newRealese.getHeadTitle()%> /td>
/tr>
tr>
td colspan="6">新聞內(nèi)容:/td>
/table>
table width="100%" border="0">
tr>
td>
a target="_blank" href="newRealese_detail.jsp?newsid=%=newRealese.getNewsId()%>"/>
table width="100%" border="0" align="center">
tr>
td>
%=newRealese.getContent()%> /td>
/tr>
/table> /td>
/tr>
/table>
table border="0" width="100%">
tr>
td width="51" height="30">作者:/td>
td width="203">%=newRealese.getAuthor()%> /td>
td width="97">新聞發(fā)布時(shí)間:/td>
td width="167">%=newRealese.getNewsTime()%> /td>
td width="99">新聞點(diǎn)擊次數(shù):/td>
td width="191">%=newRealese.getHits()%> /td>
/tr>
/table>/td>
/tr>
tr>
td height="21" colspan="2">
input type="button" name="delete" value="刪除" align="middle"
onclick="javascrtpt:window.location.href = 'DeleteOneNews?newsid=%=newRealese.getNewsId()%>'">
input type="button" name="delete" value="修改" align="middle"
onclick="javascrtpt:window.location.href = 'a_updateNews.jsp?newsid=%=newRealese.getNewsId()%>'">
hr> /td>
/tr>
/table>
%
}
%> /td>
/tr>
/table> /td>
td width="5%" style=" text-orientation: vertical-right">
%@include file="a_queryNews.jsp" %>
/td>
/tr>
tr>
td align="center">a href="a_addNews.jsp" target="_blank">添加新聞/a>/td>
td align="center">二/td>
td align="center">三/td>
/tr>
/table>
/body>
/html>
(6)增加新聞頁(yè)面,命名為a_addNews.jsp,能夠進(jìn)行新聞的增加,在添加完信息之后,我們點(diǎn)擊發(fā)布之后就可以成功添加信息,其代碼如下所示,增加新聞時(shí)需要對(duì)新聞進(jìn)行編輯,對(duì)于長(zhǎng)篇幅新聞內(nèi)容且含有圖片的新聞內(nèi)容的編寫(xiě),在這兒我們使用功能強(qiáng)大的百度編輯器,首先從官網(wǎng)下載:百度編輯器下載,下載之后解壓(我使用的版本是ueditor1_4_3_2-utf8-jsp),如下圖所示結(jié)構(gòu)
圖10 百度富文本編輯器文件夾結(jié)構(gòu)圖
然后只需將整個(gè)文件夾拷貝到項(xiàng)目下即可,在使用時(shí)引入和修改路徑,在jsp頁(yè)面里邊我已經(jīng)配置好引用,只需修改路徑即可,修改路徑時(shí)只需將editor_config.js中查找URL變量配置編輯器在你項(xiàng)目中的路徑。其中./ueditor為項(xiàng)目中的文件夾
var URL= window.UEDITOR_HOME_URL||"./ueditor/";
這樣就配置好了編輯器,下面就是增加新聞的jsp頁(yè)面,在添加完新聞之后,只需點(diǎn)擊發(fā)布即可進(jìn)行新聞的發(fā)布操作,代碼如下所示:
%@page contentType="text/html" import="java.util.*,java.sql.*" pageEncoding="UTF-8" language="java"%>
%@page import="com.lut.beans.NewsRealese" %>
%@page import="dao.NewsRealeseDao" %>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>添加新聞- 新聞發(fā)布系統(tǒng)--最前沿的時(shí)尚信息、最有看點(diǎn)的社會(huì)聚焦、最富得浪漫的殿tang/title>
!-- 配置文件 -->
script type="text/javascript" src="./ueditor/ueditor.config.js">/script>
!-- 編輯器源碼文件 -->
script type="text/javascript" src="./ueditor/ueditor.all.js">/script>
link rel="stylesheet" type="text/css" href="./udeditor/themes/default/css" />
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
/head>
body id="body">
form action="InsertOneNews" method="post">
table border="0" id="table">
tr>
td width="5%">left/td>
td width="90%">
table border="1" id="table">
tr >
td >新聞編號(hào)/td> td>input type="text" name="newsid">/td>
td>所屬新聞欄目編號(hào)/td> td>input type="text" name="classid">/td>
/tr>
tr>
td>所屬新聞分類編號(hào)/td> td>input type="text" name="kindid">/td>
td>原創(chuàng)或轉(zhuǎn)載/td> td>input type="text" name="myother">/td>
/tr>
tr>
td>新聞標(biāo)題/td> td>input type="text" name="headtitle">/td>
td>相關(guān)文章/td> td>input type="text" name="connectrealtive">/td>
/tr>
tr>
td>作者/td> td>input type="text" name="author">/td>
td>編輯/td> td>input type="text" name="editor">/td>
/tr>
tr>
td>出處/td> td>input type="text" name="newsfrom">/td>
td>是否置頂/td> td>input type="text" name="top">/td>
/tr>
tr>
td>新聞發(fā)布時(shí)間/td> td>input type="text" name="newstime">/td>
td>新聞點(diǎn)擊次數(shù)/td> td>input type="text" name="hits">/td>
/tr>
tr>
td>新聞狀態(tài)/td> td>input type="text" name="state">/td>
td>新聞標(biāo)記/td> td>input type="text" name="tag">/td>
/tr>
tr>
/table>
/td>
td width="5%">right/td>
/tr>
tr>
td>nbsp;/td>
td>
div align="center" style="width:80%">
textarea id="newsEditor" name="content" style="height: 80%">/textarea>
br/>
input type="submit" value="發(fā) 布">
script type="text/javascript">
UE.getEditor('newsEditor');
// var content = UE.getPlainTxt();//content就是編輯器的帶格式的內(nèi)容
//focus時(shí)自動(dòng)清空初始化時(shí)的內(nèi)容
/script>
/div>
/td>
td>nbsp;/td>
/tr>
/table>
/form>
/body>
/html>
在增加新聞時(shí),需要對(duì)Servlet進(jìn)行配置,如下圖所示所示為配置文件的結(jié)構(gòu):
插入數(shù)據(jù)Servlet結(jié)構(gòu)圖
下面是InserOneNews.java代碼,能夠進(jìn)行對(duì)數(shù)據(jù)的插入功能
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import dao.NewsRealeseDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InsertOneNews extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
ArrayList addnews_list = new ArrayList();
NewsRealeseDao newsRealeseDao = new NewsRealeseDao();
addnews_list.add(0, request.getParameter("newsid"));
addnews_list.add(1, request.getParameter("classid"));
addnews_list.add(2, request.getParameter("kindid"));
addnews_list.add(3, request.getParameter("myother"));
addnews_list.add(4, request.getParameter("headtitle"));
addnews_list.add(5, request.getParameter("content"));
addnews_list.add(6, request.getParameter("connectrealtive"));
addnews_list.add(7, request.getParameter("author"));
addnews_list.add(8, request.getParameter("editor"));
addnews_list.add(9, request.getParameter("newsfrom"));
addnews_list.add(10, request.getParameter("top"));
addnews_list.add(11, request.getParameter("newstime"));
addnews_list.add(12, request.getParameter("hits"));
addnews_list.add(13, request.getParameter("state"));
addnews_list.add(14,request.getParameter("tag"));
try {
String newsRealese = newsRealeseDao.insertOneNews(addnews_list);
System.out.println("String:"+newsRealese);
if (newsRealese!= null) {
response.sendRedirect("adminManager.jsp");
} else {
response.sendRedirect("a_addNews.jsp");
}
} catch (Exception ex) {
Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
至此,我們完整的實(shí)現(xiàn)了插入工作 (7)現(xiàn)在完成刪除操作,在Servlet包中建立如下所示代碼,命名為DeleteOneNews.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import dao.NewsRealeseDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DeleteOneNews extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String str_id=request.getParameter("newsid");
int newsid_int=Integer.valueOf(str_id);
NewsRealeseDao newsRealeseDao=new NewsRealeseDao();
try {
String newsRealese = newsRealeseDao.deleteOneNews(newsid_int);
System.out.println("String:"+newsRealese);
if (newsRealese!= null) {
response.sendRedirect("adminManager.jsp");
} else {
response.sendRedirect("a_addNews.jsp");
}
} catch (Exception ex) {
Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP code>POST/code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// /editor-fold>
}
(8)實(shí)現(xiàn)查詢操作,命名為a_queryNews.jsp,其代碼如下所示:
%--
Document : a_queryNews
Created on : 2016-5-18, 17:08:40
Author : Administrator
--%>
%@page contentType="text/html" pageEncoding="UTF-8"%>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>查詢頁(yè)面/title>
/head>
body>
table style="width:100%;height:100%" border="0">
tr>
td>
form action="QueryOneNews" method="post" target="_blank" >
請(qǐng)輸入新聞編號(hào):input type="text" name="query">
input type="submit" value="查詢" >br>
/form>
hr>/td>
/tr>
tr>
td>nbsp;/td>
/tr>
/table>
/body>
/html>
對(duì)于查詢這件事,有成功,有失敗,在這兒我們進(jìn)行失敗后文件的設(shè)置,代碼如下所示,命名為a_queryNewsfailed.jsp,使用超級(jí)連接的方式,連接到主頁(yè)面
%--
Document : a_queryNeesfailed
Created on : 2016-6-6, 8:43:35
Author : Administrator
--%>
%@page contentType="text/html" pageEncoding="UTF-8"%>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>查詢失敗/title>
/head>
body>
h1>沒(méi)有找到你要查找的內(nèi)容,但是你可以進(jìn)入/h1>
a href="index.html">主頁(yè)進(jìn)行查看/a>
/body>
/html>
實(shí)現(xiàn)了以上顯示層的操作之后,下面就是控制層的實(shí)現(xiàn),命名為QueryOneNews.java,其代碼如下所示:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import dao.NewsRealeseDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class QueryOneNews extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String str_id=request.getParameter("query");
int newsid_int=Integer.valueOf(str_id);
NewsRealeseDao newsRealeseDao=new NewsRealeseDao();
try {
ArrayList newsRealese = newsRealeseDao.queryOneNews(newsid_int);
char [] s1=newsRealese.toString().toCharArray();
System.out.println("String+newsRealese:"+newsRealese);
System.out.println("String+newsRealese:"+s1[0]+" -------"+s1[1]);
if(s1[0]=='['s1[1]==']')
{
response.sendRedirect("a_queryNewsfailed.jsp");
}
else
{
response.sendRedirect("newRealese_detail.jsp?newsid="+str_id);
}
} catch (Exception ex) {
Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
(9)下面實(shí)現(xiàn)更新數(shù)據(jù)的操作,命名為a_updateNews.jsp,其代碼如下所示:
%@page contentType="text/html" import="java.util.*,java.sql.*" pageEncoding="UTF-8" language="java"%>
%@page import="com.lut.beans.NewsRealese" %>
%@page import="dao.NewsRealeseDao" %>
!DOCTYPE html>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>更改新聞-/title>
!-- 配置文件 -->
script type="text/javascript" src="./ueditor/ueditor.config.js">/script>
!-- 編輯器源碼文件 -->
script type="text/javascript" src="./ueditor/ueditor.all.js">/script>
link rel="stylesheet" type="text/css" href="./udeditor/themes/default/css" />
link type="text/css" rel="stylesheet" href="newsRealese.css"/>
/head>
body id="body">
%
NewsRealeseDao newsRealeseDao=new NewsRealeseDao();
String newsid_s=request.getParameter("newsid");
int news_int=Integer.valueOf(newsid_s);
ArrayList news_list=newsRealeseDao.queryOneNews(news_int);
%>
%
for(int i=0;inews_list.size();i++)
{
NewsRealese newRealese=(NewsRealese)news_list.get(i);
%>
form action="UpdateOneNews" method="post">
table border="0" id="table" style="width:95%">
tr>
td width="5%">left/td>
td width="90%">
table border="1" id="table" style="width:100%">
tr >
tr>
td >新聞編號(hào)/td> td>input type="text" width="100%" name="newsid" value="%=newRealese.getNewsId() %>">/td>
td>所屬新聞欄目編號(hào)/td> td>input type="text" width="100%" name="classid" value="%=newRealese.getClassId() %>">/td>
/tr>
tr>
td>所屬新聞分類編號(hào)/td> td>input type="text" width="100%" name="kindid" value="%=newRealese.getKindId() %>">/td>
td>原創(chuàng)或轉(zhuǎn)載/td> td>input type="text" width="100%" name="myother" value="%=newRealese.getMyOther() %>">/td>
/tr>
tr>
td>新聞標(biāo)題/td> td>input type="text" width="100%" name="headtitle" value="%=newRealese.getHeadTitle()%>">/td>
td>相關(guān)文章/td> td>input type="text" width="100%" name="connectrealtive" value="%=newRealese.getConnectRealtive()%>">/td>
/tr>
tr>
td>作者/td> td>input type="text" width="100%" name="author" value="%=newRealese.getAuthor() %>">/td>
td>編輯/td> td>input type="text" width="100%" name="editor" value="%=newRealese.getEditor() %>">/td>
/tr>
tr>
td>出處/td> td>input type="text" width="100%" name="newsfrom" value="%=newRealese.getNewsFrom() %>">/td>
td>是否置頂/td> td>input type="text" width="100%" name="top" value="%=newRealese.getTop() %>">/td>
/tr>
tr>
td>新聞發(fā)布時(shí)間/td> td>input type="text" width="100%" name="newstime" value="%=newRealese.getNewsTime() %> ">/td>
td>新聞點(diǎn)擊次數(shù)/td> td>input type="text" width="100%" name="hits" value="%=newRealese.getHits() %>">/td>
/tr>
tr>
td>新聞狀態(tài)/td> td>input type="text" name="state" width="100%" value="%=newRealese.getState() %>">/td>
td>新聞標(biāo)記/td> td>input type="text" width="100%" name="tag" value="%=newRealese.getTag() %>">/td>
/tr>
tr>
/table>
/td>
td width="5%">right/td>
/tr>
tr>
td>nbsp;/td>
td>
div align="center" style="width:80%">
textarea id="newsEditor" name="content" style="height: 80%">%=newRealese.getContent() %>/textarea>
br/>
input type="submit" value="發(fā) 布">
script type="text/javascript">
UE.getEditor('newsEditor');
var content=UE.getPlainTxt();//s就是編輯器的帶格式的內(nèi)容
/script>
/div>
/td>
td>nbsp;/td>
/tr>
/table>
/form>
%
}
%>
/body>
/html>
在Servlet中進(jìn)行如下代碼所示配置:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import dao.NewsRealeseDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UpdateOneNews extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
ArrayList addnews_list = new ArrayList();
NewsRealeseDao newsRealeseDao = new NewsRealeseDao();
addnews_list.add(0, request.getParameter("newsid"));
addnews_list.add(1, request.getParameter("classid"));
addnews_list.add(2, request.getParameter("kindid"));
addnews_list.add(3, request.getParameter("myother"));
addnews_list.add(4, request.getParameter("headtitle"));
addnews_list.add(5, request.getParameter("content"));
addnews_list.add(6, request.getParameter("connectrealtive"));
addnews_list.add(7, request.getParameter("author"));
addnews_list.add(8, request.getParameter("editor"));
addnews_list.add(9, request.getParameter("newsfrom"));
addnews_list.add(10, request.getParameter("top"));
addnews_list.add(11, request.getParameter("newstime"));
addnews_list.add(12, request.getParameter("hits"));
addnews_list.add(13, request.getParameter("state"));
addnews_list.add(14,request.getParameter("tag"));
try {
String newsRealese = newsRealeseDao.updateOneNews(addnews_list);
System.out.println("String:"+newsRealese);
if (newsRealese!= null) {
response.sendRedirect("adminManager.jsp");
} else {
response.sendRedirect("a_addNews.jsp");
}
} catch (Exception ex) {
Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
到這兒,我們已經(jīng)實(shí)現(xiàn)了對(duì)增刪改查功能的實(shí)現(xiàn),當(dāng)然,基本的新聞發(fā)布功能已經(jīng)實(shí)現(xiàn)
關(guān)于管理系統(tǒng)的更多內(nèi)容請(qǐng)點(diǎn)擊《管理系統(tǒng)專題》進(jìn)行學(xué)習(xí)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- VueJS實(shí)現(xiàn)用戶管理系統(tǒng)
- Node.js實(shí)現(xiàn)簡(jiǎn)單管理系統(tǒng)
- jdbc+jsp實(shí)現(xiàn)簡(jiǎn)單員工管理系統(tǒng)
- JSP實(shí)現(xiàn)簡(jiǎn)單人事管理系統(tǒng)
- JSP實(shí)現(xiàn)客戶信息管理系統(tǒng)
- JSP學(xué)生信息管理系統(tǒng)設(shè)計(jì)
- 詳解nodejs中express搭建權(quán)限管理系統(tǒng)
- 如何使用AngularJs打造權(quán)限管理系統(tǒng)【簡(jiǎn)易型】
- JSP學(xué)生信息管理系統(tǒng)
- js實(shí)現(xiàn)車輛管理系統(tǒng)