一.下拉框数据绑定
目的:我们插入两条一样的新闻,那么要将数据绑定到页面。
<%
//定义全局变量,
//int nid=0;
int ntid=0;
String ntitle = "";
String ndate = "";
String nauthor = "";
String nsummary = "";
String ncontent = "";
int ncount = 0;
//设置编码格式
request.setCharacterEncoding("utf-8");
//2.获取参数
String id = request.getParameter("nid");
int nid = 0;
if (null != id) {
nid = Integer.valueOf(id);//转成int类型 因为数据库number类型
}
//数据库交互
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//sql
String sql = "select * from tb_t281_news where nid=" + nid;
//连接对象
PreparedStatement ps = conn.prepareStatement(sql);
//结果集对象
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ntid=rs.getInt(2);
ntitle = rs.getString(3);
nauthor = rs.getString(4);
nsummary = rs.getString(5);
ncontent = rs.getString(6);
ndate = rs.getString(8);
ncount = rs.getInt(9);
}
%>
<!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 rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>
<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">管理员: 登录     <a href="#">退出</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="admin.html">管 理 首 页</a></li>
<li><a href="admin_addNews.html">新 闻 发 布</a></li>
<li><a href="admin_themeMaintain.html">主 题 维 护</a></li>
<li><a style="color: red;" href="#">系统账号管理</a></li>
<li><a style="color: red;" href="#">注册用户管理</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 编辑新闻: </h1>
<form action="doadmin_editNews.jsp?nid=<%=nid %>" method="post">
<p>
<label> 主题 </label>
<select name="ntid">
<option value="1">选择</option>
<%
//绑定新闻分类主题
sql="select * from tb_t281_news_themes";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
if(rs.getInt(1)==nid){
out.println("<option selected='selected' value="+rs.getInt(1)+">"+rs.getString(2)+"</option>");
}else{
out.println("<option value="+rs.getInt(1)+">"+rs.getString(2)+"</option>");
}
}
%>
</select>
二、删除功能全部展示:
<%
//定义sql语句
sql = "select * from zt order by tid";
//获得执行对象
ps = con.prepareStatement(sql);
//获得结果集
rs = ps.executeQuery();
//循环遍历
while(rs.next()){
//做判断
if(rs.getInt(1)==tid){
out.print("<option selected='selected' value='"+rs.getInt(1)+"'>"+rs.getString(2)+"</option>");//输送到页面
}
else{
out.print("<option value='"+rs.getInt(1)+"'>"+rs.getString(2)+"</option>");//输送到页面
}
}
//关闭资源
if(con!=null&&!con.isClosed()){
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
%>
删除的doDelNews.jsp页面
<%@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"%>
<%
//doDelNews.jsp 作用:获取编号进行删除(数据库交互)
//1.设置reuqest请求的编码格式
request.setCharacterEncoding("utf-8");
//2.获取location拼接的参数 新闻编号
String id = request.getParameter("nid");
int nid = 0;
if (null != id) {
nid = Integer.valueOf(id);//转成int类型 因为数据库number类型
}
//out.println("编号为: "+nid);
//3.数据库交互 根据获取的新闻编号进行删除
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//sql
String sql = "delete from tb_t281_news where nid = "+nid;
PreparedStatement ps = conn.prepareStatement(sql);
//返回所影响的行数
int n = ps.executeUpdate();
//4.根据所影响的行数进行判断跳转到指定的页面
if(n>0){
out.println("<script>alert('删除成功');location.href='adminHome.jsp'</script>");
}else{
out.println("<script>alert('删除失败');location.href='adminHome.jsp'</script>");
}
%>
三、修改功能全部展示:
修改的AdminEditNews.jsp主页面
<%@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"%>
<%
//定义全局变量,
//int nid=0;
int ntid=0;
String ntitle = "";
String ndate = "";
String nauthor = "";
String nsummary = "";
String ncontent = "";
int ncount = 0;
//设置编码格式
request.setCharacterEncoding("utf-8");
//2.获取参数
String id = request.getParameter("nid");
int nid = 0;
if (null != id) {
nid = Integer.valueOf(id);//转成int类型 因为数据库number类型
}
//数据库交互
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//sql
String sql = "select * from tb_t281_news where nid=" + nid;
//连接对象
PreparedStatement ps = conn.prepareStatement(sql);
//结果集对象
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ntid=rs.getInt(2);
ntitle = rs.getString(3);
nauthor = rs.getString(4);
nsummary = rs.getString(5);
ncontent = rs.getString(6);
ndate = rs.getString(8);
ncount = rs.getInt(9);
}
%>
<!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 rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>
<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">管理员: 登录     <a href="#">退出</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="admin.html">管 理 首 页</a></li>
<li><a href="admin_addNews.html">新 闻 发 布</a></li>
<li><a href="admin_themeMaintain.html">主 题 维 护</a></li>
<li><a style="color: red;" href="#">系统账号管理</a></li>
<li><a style="color: red;" href="#">注册用户管理</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 编辑新闻: </h1>
<form action="doadmin_editNews.jsp?nid=<%=nid %>" method="post">
<p>
<label> 主题 </label>
<select name="ntid">
<option value="1">选择</option>
<%
//绑定新闻分类主题
sql="select * from tb_t281_news_themes";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
if(rs.getInt(1)==nid){
out.println("<option selected='selected' value="+rs.getInt(1)+">"+rs.getString(2)+"</option>");
}else{
out.println("<option value="+rs.getInt(1)+">"+rs.getString(2)+"</option>");
}
}
%>
</select>
</p>
<p>
<label> 标题 </label>
<input name="ntitle" type="text" class="opt_input" value="<%=ntitle %>" />
</p>
<p>
<label> 作者 </label>
<input name="nauthor" type="text" class="opt_input" value="<%=nauthor %>" />
</p>
<p>
<label> 摘要 </label>
<textarea name="nsummary" cols="40" rows="3"><%=nsummary %></textarea>
</p>
<p>
<label> 内容 </label>
<textarea name="ncontent" cols="70" rows="10"><%=ncontent %></textarea>
</p>
<p>
<label> 上传图片 </label>
<input name="file" type="file" class="opt_input" />
</p>
<input name="nid" 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>
修改的doAdminEditNews.jsp加载页面
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//1.设置编码
request.setCharacterEncoding("utf-8");
//2.获取表单提交的值
//新闻编号
String id = request.getParameter("nid");
int nid = 0;
if (null != id) {
nid = Integer.valueOf(id);//转成int类型 因为数据库number类型
}
//新闻分类编号
String tid = request.getParameter("ntid");
int ntid = 0;
if (null != tid) {
ntid = Integer.valueOf(tid);//转成int类型 因为数据库number类型
}
//标题
String ntitle = request.getParameter("ntitle");
//作者
String nauthor = request.getParameter("nauthor");
//摘要
String nsummary = request.getParameter("nsummary");
//内容
String ncontent = request.getParameter("ncontent");
//时间
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ndate = sdf.format(date);
//点击量 不写
//3.数据库交互修改
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//sql
String sql = "update tb_t281_news set ntid = ? , ntitle = ? , nauthor = ? , nsummary = ? , ncontent = ? , ndate = to_date(?,'yyyy-mm-dd hh24:mi:ss') where nid = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1,ntid);
ps.setString(2,ntitle);
ps.setString(3,nauthor);
ps.setString(4,nsummary);
ps.setString(5,ncontent);
ps.setString(6,ndate);
ps.setInt(7,nid);
//返回所影响的行数
int n = ps.executeUpdate();
//4.跳转页面
if(n>0){
out.println("<script>alert('修改成功');location.href='adminHome.jsp'</script>");
}else{
out.println("<script>alert('修改失败');location.href='adminHome.jsp?nid="+nid+"'</script>");
}
%>
四、超链接上涉及到点击事件,要阻止超链接本身跳转
<!-- <a href='doDeleteNews.jsp?nid=< % =rs.getInt(1)%>'></a> -->
<a href='javascript:void(0)' οnclick='clickdel()'>删除</a>
五、新闻发布功能实现
新闻发布系统-后台主页【adminHome.jsp】
<%@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>
<html>
<head>
<meta charset="UTF-8">
<title>新闻发布系统-后台主页</title>
<link rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>
<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">管理员:<%=request.getParameter("username") %>      <a href="#">login out</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="admin.html">管 理 首 页</a></li>
<li><a href="adminAddNews.jsp">新 闻 发 布</a></li>
<li><a href="admin_themeMaintain.html">主 题 维 护</a></li>
<li><a href="admin_themeMaintain.html">评 论 管 理</a></li>
<li><a style="color: red;" href="#">系统账号管理</a></li>
<li><a style="color: red;" href="#">注册用户管理</a></li>
</ul>
</div>
<div id="opt_area">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="javascript">
function clickdel(nid) {
//alert(typeof(nid));
//通过location.href进行跳转到do页面进行处理删除 返回admin.jsp即可
if(window.confirm("你确定要删除该篇新闻吗?") == true){
window.location.href = "doDelNews.jsp?nid="+nid;
}
}
</script>
<!-- 功能:显示所有新闻 start-->
<ul class="classlist">
<%
//数据库交互oracleDriver
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","123");
//sql
String sql = "select * from tb_t281_news";
PreparedStatement ps = conn.prepareStatement(sql);
//返回结果集对象
ResultSet rs = ps.executeQuery();
//遍历
while(rs.next()){
%>
<!-- out.println("<li></li>"); -->
<li>
<a href="adminNewsDetail.jsp?nid=<%=rs.getInt(1)%>"><%=rs.getString(3) %></a>
<span> 作者:<%=rs.getString(4) %>
    
<a href='adminEditNews.jsp?nid=<%=rs.getInt(1)%>'>修改</a>
    
<!-- 超链接上涉及到点击事件,阻止超链接本身跳转 -->
<!-- <a href = 'doDeleteNews.jsp?nid=< %=rs.getInt(1) % >'></a> -->
<a href='javascript:void(0)' onclick='clickdel("<%=rs.getInt(1)%>")'>删除</a>
</span>
</li>
<%
}
%>
<p align="right"> 当前页数:[1/3] <a href="#">下一页</a> <a href="#">末页</a> </p>
</ul>
<!-- 功能:显示所有新闻 end-->
</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>
【小功能:下面是显示所有新闻】
<div id="opt_area">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="javascript">
function clickdel(nid) {
//alert(typeof(nid));
//通过location.href进行跳转到do页面进行处理删除 返回admin.jsp即可
if(window.confirm("你确定要删除该篇新闻吗?") == true){
window.location.href = "doDelNews.jsp?nid="+nid;
}
}
</script>
<!-- 功能:显示所有新闻 start-->
<ul class="classlist">
<%
//数据库交互oracleDriver
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","123");
//sql
String sql = "select * from tb_t281_news";
PreparedStatement ps = conn.prepareStatement(sql);
//返回结果集对象
ResultSet rs = ps.executeQuery();
//遍历
while(rs.next()){
%>
<!-- out.println("<li></li>"); -->
<li>
<a href="adminNewsDetail.jsp?nid=<%=rs.getInt(1)%>"><%=rs.getString(3) %></a>
<span> 作者:<%=rs.getString(4) %>
    
<a href='adminEditNews.jsp?nid=<%=rs.getInt(1)%>'>修改</a>
    
<!-- 超链接上涉及到点击事件,阻止超链接本身跳转 -->
<!-- <a href = 'doDeleteNews.jsp?nid=< %=rs.getInt(1) % >'></a> -->
<a href='javascript:void(0)' onclick='clickdel("<%=rs.getInt(1)%>")'>删除</a>
</span>
</li>
<%
}
%>
//注意:java<% %>中不能识别js代码需要加<% %>拼接
/*
编写格式: <%
代码段 %>
<%
代码段
%>
*/
发布功能adminAddNews.jsp主页面
<%@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>
<html>
<head>
<meta charset="UTF-8">
<title>新闻发布--管理后台</title>
<link rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>
<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">管理员: 登录     <a href="#">退出</a></div>
<div id="channel"> </div>
</div>
<div id="main">
<div id="opt_list">
<ul>
<li><a href="admin.html">管 理 首 页</a></li>
<li><a href="admin_addNews.html">新 闻 发 布</a></li>
<li><a href="admin_themeMaintain.html">主 题 维 护</a></li>
<li><a style="color: red;" href="#">系统账号管理</a></li>
<li><a style="color: red;" href="#">注册用户管理</a></li>
</ul>
</div>
<div id="opt_area">
<h1 id="opt_type"> 添加新闻: </h1>
<form action="doAdminAddNews.jsp" method="post">
<p>
<label> 主题 </label>
<select name="ntid">
<!-- 功能:发布新闻的主题下拉框数据绑定 -->
<%
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//调用方法返回执行对象
String sql ="select * from tb_t281_news_themes";
PreparedStatement ps = conn.prepareStatement(sql);
//返回结果集对象
ResultSet rs = ps.executeQuery();
while(rs.next()){
out.println("<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>
发布的doAdminAddNews.jsp加载页面
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@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"%>
<%
//发布新闻的do处理页面
//1.设置编码
request.setCharacterEncoding("utf-8");
//2.获取参数
//新闻编号问题:
//(1)oracle中没有标识列 可以进行模拟
//(2)①oracle序列+oracle触发器--模拟自增长 ②时刻获取该表中最大的主键后+1重新赋值
//新闻编号
//时刻获取该表中最大的主键后+1重新赋值
int nid = 0;//保存最终的新闻编号
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
//调用方法返回执行对象
String sql = "select nvl(max(nid),0) from tb_t281_news";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
nid = rs.getInt(1) + 1;
}
//打印
//out.println("最新编号: " + nid);
//新闻分类编号
int ntid = Integer.valueOf(request.getParameter("ntid"));
//标题
String ntitle = request.getParameter("ntitle");
//作者
String nauthor = request.getParameter("nauthor");
//摘要
String nsummary = request.getParameter("nsummary");
//内容
String ncontent = request.getParameter("ncontent");
//图片--不涉及
String nimage = "images\\1.jpg";
//注册时间
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ndate = sdf.format(date);
//点击量 0
int ncount = 0;
//3.交互--发布新闻
sql = "insert into tb_t281_news values (?,?,?,?,?,?,?,to_date(?,'yyyy-mm-dd hh24:mi:ss'),?)";
ps = conn.prepareStatement(sql);
ps.setInt(1,nid);
ps.setInt(2,ntid);
ps.setString(3,ntitle);
ps.setString(4,nauthor);
ps.setString(5,nsummary);
ps.setString(6,ncontent);
ps.setString(7,nimage);
ps.setString(8,ndate);
ps.setInt(9,ncount);
int n = ps.executeUpdate();
//4.页面跳转
if(n>0){
out.println("<script>alert('发布成功');location.href='adminHome.jsp'</script>");
}else{
out.println("<script>alert('发布失败');location.href='adminAddNews.jsp'</script>");
}
%>