主题新闻-新闻系统之新闻维护+主题维护

主页:admin.jsp 绑定数据以及点击事件(模糊查询),包括页面跳转 主页可以跳转到 添加新闻news.jsp页面,删除新闻del.jsp页面,修改新闻update.jsp页面,新闻详情xq.jsp页面,修改主题xgzt.jsp页面,增加主题addzt.jsp

<title>添加主题--管理后台</title>
<link href="CSS/admin.css" rel="stylesheet" type="text/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">
			管理员: 登录 &#160;&#160;&#160;&#160; <a href="login.jsp">登录</a>
		</div>
		<div id="channel"></div>
	</div>
	<div id="main">
		<div id="opt_list">
			<ul>
				<li><a href="newspages/add_news.jsp">添加新闻</a></li>
				<li><a href="newspages/read_news.jsp">编辑新闻</a></li>
				<li><a href="#">查找新闻</a></li>
				<li><a href="newspages/add_sub.jsp">添加主题</a></li>
				<li><a href="newspages/add_subup.jsp">编辑主题</a></li>
			</ul>
		</div>
		<div id="opt_area">
			<!-- 删除提示 -->
			<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">
	
				<%
				
				//设置编码-设置请求对象的编号
				request.setCharacterEncoding("utf-8");
				
				//获取模糊查询的关键字
				 String str = request.getParameter("str");
    if(str==null){
    	str = "";
    }
    String sql = "select * from news where ntitle like '%"+str+"%' order by nid desc";
    //连接数据库查询新闻信息
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
	Connection con = DriverManager.getConnection(url, "sa", "1234");
	PreparedStatement ps = con.prepareStatement(sql);
	ResultSet rs= ps.executeQuery();
	while(rs.next()){
				%>			
				<li>
				<a href="newspages/read_newsjsp.jsp?nid=<%=rs.getInt(1)%>">
				<%=rs.getString("ntitle")%> 
				</a>

				 作者: <%=rs.getString("nzz")%>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
						 <a href='newspages/up_news.jsp?nid=<%=rs.getInt(1)%>'>修改</a>
						&#160;&#160;&#160;&#160; 
						<a href='del_news.jsp?nid=<%=rs.getInt(1)%>'
						onclick='return clickdel()'>删除</a>
				</span></li>
				<li class='space'></li>
				<%}
				%>
				  <p align="right"> 当前页数:[1/3]&nbsp; <a href="#">下一页</a> <a href="#">末页</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 &#160;&#160;&#160;&#160; <a href="#">常见问题解答</a>
			&#160;&#160;&#160;&#160; 新闻热线:010-627488888<br />
			文明办网文明上网举报电话:010-627488888 &#160;&#160;&#160;&#160; 举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a>
		</p>
		<p class="copyright">
			Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
			新闻中国 版权所有
		</p>
	</div>
</body>
</html>

添加新闻,这里是通过from表单提交滴从news.jsp传到donews.jsp哟

下面是news.jsp

↓↓↓↓↓↓↓↓↓↓↓↓↓↓

​
<title>添加主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/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">管理员: 登录  &#160;&#160;&#160;&#160;<a href="#">login out</a></div>
  <div id="channel"> </div>
</div>
<div id="main">
  <div id="opt_list">
    <ul>
      <li><a href="newspages/add_news.jsp">添加新闻</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 id="opt_area">
    <h1 id="opt_type"> 添加新闻: </h1>
    <form action="../doadd_news.jsp" method="post">
      <p>
        <label> 主题 </label>
        <!-- 为了提交要记住ntid -->
        <select name="ntid">
       <%
		//链接数据库,查询新闻
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
		Connection con = DriverManager.getConnection(url, "sa", "1234");
		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  &#160;&#160;&#160;&#160; <a href="#">常见问题解答</a> &#160;&#160;&#160;&#160;  新闻热线:010-627488888<br />
    文明办网文明上网举报电话:010-627488888  &#160;&#160;&#160;&#160;  举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
  <p class="copyright">Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
    新闻中国   版权所有</p>
</div>
</body>
</html>

​

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

下面是do_news.jsp


//设置编码-设置请求对象的编号
request.setCharacterEncoding("utf-8");

//添加接收添加的页面的数据
//新闻主题编号
int tid = Integer.valueOf(request.getParameter("ntid"));
//新闻标题
String ntitle=request.getParameter("ntitle");
//新闻作者
String nzz=request.getParameter("nauthor");
//新闻摘要
String nzy=request.getParameter("nsummary");
//新闻内容
String nnr=request.getParameter("ncontent");
//时间
//String nsj=request.getParameter("time");

//链接数据库,查询新闻
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
Connection con = DriverManager.getConnection(url, "sa", "1234");
//获取新闻的下一个编号
int nextNid=1;
PreparedStatement ps = con.prepareStatement("select max(nid) from news");
ResultSet rs = ps.executeQuery();
if(rs.next()){
	nextNid=rs.getInt(1)+1;
}

ps = con.prepareStatement("insert into news values(?,?,?,?,?,Datename(year,GetDate())+'-'+Datename(month,GetDate())+'-'+Datename(day,GetDate()),0,?)");
ps.setInt(1, nextNid);
ps.setInt(2, tid);
ps.setString(3, ntitle);
ps.setString(4, nzz);
ps.setString(5,nzy);
ps.setString(6,nnr);


//执行sql语句
int i = ps.executeUpdate();
if (i > 0) {
	out.print("<script>alert('添加成功');location.href='admin.jsp'</script>");
} else {
	out.print("<script>alert('添加失败');location.href='add_news.jsp'</script>");
}
%>

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

下面是update.jsp修改页面

<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>
<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">管理员: 登录  &#160;&#160;&#160;&#160;<a href="#">login out</a></div>
  <div id="channel"> </div>
</div>
<div id="main">
  <div id="opt_list">
    <ul>
      <li><a href="news_add.jsp">添加新闻</a></li>
      <li><a href="../admin.jsp">编辑新闻</a></li>
      <li><a href="#">查找新闻</a></li>
      <li><a href="topic_add.jsp">添加主题</a></li>
      <li><a href="#">编辑主题</a></li>
    </ul>
  </div>
  <div id="opt_area">
    <h1 id="opt_type"> 添加新闻: </h1>
    <form action="doupdate.jsp?nid<%=request.getParameter("nid") %>" method="post">
      <p>
        <label> 主题 </label>
         <%
         Class.forName("oracle.jdbc.OracleDriver");
         String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
         Connection con = DriverManager.getConnection(url, "scott", "1234");
         PreparedStatement ps = con.prepareStatement("select * from News where nid= "+request.getParameter("nid"));
         ResultSet rs = ps.executeQuery();
         while(rs.next()){
         %>
      </p>
      <p>
        <label> 标题 </label>
        <input name="ntitle" type="text" class="opt_input" value=<%=rs.getString(3)%>/>
      </p>
      <p>
        <label> 作者 </label>
        <input name="nauthor" type="text" class="opt_input" value=<%=rs.getString(4)%>/>
      </p>
      <p>
        <label> 摘要 </label>
        <textarea name="nsummary" cols="40" rows="3" ><%=rs.getString(7)%></textarea>
      </p>
      <p>
        <label> 内容 </label>
        <textarea name="ncontent" cols="70" rows="10" ><%=rs.getString(5)%></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  &#160;&#160;&#160;&#160; <a href="#">常见问题解答</a> &#160;&#160;&#160;&#160;  新闻热线:010-627488888<br />
    文明办网文明上网举报电话:010-627488888  &#160;&#160;&#160;&#160;  举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
  <p class="copyright">Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
    新闻中国   版权所有</p>
</div>
</body>
</html>

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

下面是doupdate.jsp修改页面

<%
String tid = request.getParameter("ntid");
int ntid = Integer.valueOf(tid);
String ntitle = request.getParameter("ntitle");
String nauthor = request.getParameter("nauthor");
String nsummary = request.getParameter("nsummary");
String ncontent = request.getParameter("ncontent");
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
Connection con = DriverManager.getConnection(url, "scott", "wearegood000");
int mtid = 1;
PreparedStatement ps = con.prepareStatement("select max(tid) from news");
ResultSet rs = ps.executeQuery();
if(rs.next()){
	mtid = rs.getInt(1)+1;
}
 
PreparedStatement ps1 = con.prepareStatement("update News set  ntitle=?,nauthor=?,nsumary=?,ncontent=?  where nid="+request.getParameter("nid"));
ps1.setString(1, ntitle);
ps1.setString(2, nauthor);
ps1.setString(3, nsummary);
ps1.setString(4, ncontent);
ResultSet rs1 = ps1.executeQuery();
if(rs1.next()){
	out.print("<script>alert('修改成功');location.href='../admin.jsp'</script>");
}else{
	out.print("<script>alert('修改失败');location.href='update.jsp'</script>");
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

下面是del删除页面

<%
String nid = request.getParameter("nid");
int sid = Integer.valueOf(nid);
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
Connection con = DriverManager.getConnection(url, "scott", "wearegood000");
PreparedStatement ps = con.prepareStatement("delete News where nid=?");
ps.setInt(1, sid);
int i = ps.executeUpdate();
if(i>0){
	out.print("<script>alert('删除成功');location.href='admin.jsp'</script>");
}else{
	out.print("<script>alert('删除失败');location.href='admin.jsp'</script>");
}
%>

下面是详情xq.jsp页面

<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>
<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">管çåï¼ ç»å½  &#160;&#160;&#160;&#160;<a href="#">login out</a></div>
  <div id="channel"> </div>
</div>
<div id="main">
  <div id="opt_list">
    <ul>
      <li><a href="news_add.jsp">æ·»å æ°é»</a></li>
      <li><a href="../admin.jsp">ç¼è¾æ°é»</a></li>
      <li><a href="#">æ¥æ¾æ°é»</a></li>
      <li><a href="topic_add.jsp">æ·»å 主é¢</a></li>
      <li><a href="#">ç¼è¾ä¸»é¢</a></li>
    </ul>
  </div>
  <div id="opt_area">
    <h1 id="opt_type"> æ·»å æ°é»ï¼ </h1>
    <form action="admin.jsp" method="post">
      <p>
        <label> ä¸»é¢ </label>
         <%
         Class.forName("oracle.jdbc.OracleDriver");
         String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
         Connection con = DriverManager.getConnection(url, "scott", "1234");
         PreparedStatement ps = con.prepareStatement("select * from News where nid= "+request.getParameter("nid"));
         ResultSet rs = ps.executeQuery();
         while(rs.next()){
         %>
      </p>
      <p>
        <label> æ é¢ </label>
        <input name="ntitle" type="text" class="opt_input" readonly="readonly" value=<%=rs.getString(3)%>/>
      </p>
      <p>
        <label> ä½è </label>
        <input name="nauthor" type="text" class="opt_input" readonly="readonly" value=<%=rs.getString(4)%>/>
      </p>
      <p>
        <label> æè¦ </label>
        <textarea name="nsummary" cols="40" rows="3" readonly="readonly"><%=rs.getString(7)%></textarea>
      </p>
      <p>
        <label> å容 </label>
        <textarea name="ncontent" cols="70" rows="10" readonly="readonly">><%=rs.getString(5)%></textarea>
      </p>
         <%}%>
      <p>
        <label> ä¸ä¼ å¾ç </label>
        <input name="file" type="file" class="opt_input" />
      </p>
      <input name="action" type="hidden" value="addnews">
      <input type="button" 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  &#160;&#160;&#160;&#160; <a href="#">常è§é®é¢è§£ç­</a> &#160;&#160;&#160;&#160;  æ°é»ç­çº¿ï¼010-627488888<br />
    ææåç½ææä¸ç½ä¸¾æ¥çµè¯ï¼010-627488888  &#160;&#160;&#160;&#160;  举æ¥é®ç®±ï¼<a href="#">jubao@jb-aptech.com.cn</a></p>
  <p class="copyright">Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
    æ°é»ä¸­å½   çæææ</p>
</div>
</body>
</html>

下面是修改主题页面

<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>
<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">管理员: 登录  &#160;&#160;&#160;&#160;<a href="#">login out</a></div>
  <div id="channel"> </div>
</div>
<div id="main">
  <div id="opt_list">
    <ul>
      <li><a href="../news_add.jsp">添加新闻</a></li>
      <li><a href="../admin.jsp">编辑新闻</a></li>
      <li><a href="#">查找新闻</a></li>
      <li><a href="topic_add.jsp">添加主题</a></li>
      <li><a href="#">编辑主题</a></li>
    </ul>
  </div>
  <div id="opt_area">
    <h1 id="opt_type"> 修改主题: </h1>
    <form action="../upsub_news.jsp" method="post">
      主题:<select name="tid">
    <%
    

  //链接数据库,查询新闻
  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
  Connection con = DriverManager.getConnection(url, "sa", "1234");
  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>
      <label>改为:</label>

        <input name="tname" 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  &#160;&#160;&#160;&#160; <a href="#">常见问题解答</a> &#160;&#160;&#160;&#160;  新闻热线:010-627488888<br />
    文明办网文明上网举报电话:010-627488888  &#160;&#160;&#160;&#160;  举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
  <p class="copyright">Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
    新闻中国   版权所有</p>
</div>
</body>

修改页面

<% 

//设置编码-设置请求对象的编号
request.setCharacterEncoding("utf-8");
//添加接收添加的页面的数据
//新闻主题编号
int tid = Integer.valueOf(request.getParameter("tid"));
String tname=request.getParameter("tname");
//链接数据库,查询新闻
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
Connection con = DriverManager.getConnection(url, "sa", "1234");

//用一个隐藏的标签接收 (在up_news.jsp中)
PreparedStatement ps = con.prepareStatement("update subject set tname=? where tid="+tid);
ps.setString(1, tname);

//执行sql语句
int i = ps.executeUpdate();
if (i > 0) {
	out.print("<script>alert('修改成功');location.href='admin.jsp'</script>");
} else {
	out.print("<script>alert('修改失败');location.href='add_subup.jsp'</script>");
}
%>

添加主题

<title>添加主题--管理后台</title>
<link href="../CSS/admin.css" rel="stylesheet" type="text/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">管理员: 登录  &#160;&#160;&#160;&#160;<a href="#">login out</a></div>
  <div id="channel"> </div>
</div>
<div id="main">
  <div id="opt_list">
    <ul>
      <li><a href="../news_add.jsp">添加新闻</a></li>
      <li><a href="../admin.jsp">编辑新闻</a></li>
      <li><a href="#">查找新闻</a></li>
      <li><a href="topic_add.jsp">添加主题</a></li>
      <li><a href="#">编辑主题</a></li>
    </ul>
  </div>
  <div id="opt_area">
    <h1 id="opt_type"> 添加主题: </h1>
    <form action="../addzt_news.jsp" method="post">
      <p>
       <!-- 为了提交要记住ntid -->
        <select name="ntid">
           <%
		//链接数据库,查询新闻
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
		Connection con = DriverManager.getConnection(url, "sa", "1234");
		PreparedStatement ps = con.prepareStatement("select * from subject");
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
       
       %>
      <!-- 编号是唯一的 -->
       <option value='<%=rs.getInt(1) %>'><%=rs.getString(2) %></option>
		<%} %>
		   </select>
        <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  &#160;&#160;&#160;&#160; <a href="#">常见问题解答</a> &#160;&#160;&#160;&#160;  新闻热线:010-627488888<br />
    文明办网文明上网举报电话:010-627488888  &#160;&#160;&#160;&#160;  举报邮箱:<a href="#">jubao@jb-aptech.com.cn</a></p>
  <p class="copyright">Copyright &copy; 1999-2009 News China gov, All Right Reserver<br />
    新闻中国   版权所有</p>
</div>
</body>
</html>

添加主题

<% 

//设置编码-设置请求对象的编号
request.setCharacterEncoding("utf-8");
//添加接收添加的页面的数据
//新闻主题编号
//int tid = Integer.valueOf(request.getParameter("ntid"));
//新闻标题
//String ntitle=request.getParameter("nauthor");
String sname=request.getParameter("nauthor");

//链接数据库,查询新闻
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;DataBaseName=T277";
Connection con = DriverManager.getConnection(url, "sa", "1234");

//获取新闻的下一个编号
int nextTid=1;
PreparedStatement ps = con.prepareStatement("select max(tid) from subject");
ResultSet rs = ps.executeQuery();
if(rs.next()){
	nextTid=rs.getInt(1)+1;
}

ps=con.prepareStatement("insert into subject values(?,?)");
ps.setInt(1, nextTid);
ps.setString(2, sname);
//执行sql语句
int i = ps.executeUpdate();
if (i > 0) {
	out.print("<script>alert('添加成功');location.href='admin.jsp'</script>");
} else {
	out.print("<script>alert('添加失败');location.href='add_sub.jsp'</script>");
}
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值