<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="conn" scope="page" class="news.conn"/>
<%!
String id = "";
String title = "";
String title1 = "";
String content = "";
String keyw = "";
String author = "";
boolean flag1=false;
boolean flag2=false;
boolean flag3=false;
boolean flag4=false;
boolean flag5=false;
String sql = "";
ResultSet rs = null;
%>
<link rel="stylesheet" type="text/css" href="news.css">
<%
request.setCharacterEncoding("GBK");
if(request.getParameter("id")!=null)     {
	flag1=true; id = request.getParameter("id");
}
if(request.getParameter("title")!=null)  {
	flag2=true; title = request.getParameter("title");
}
if(request.getParameter("body")!=null)   {
	flag3=true; content = request.getParameter("body");  
}
if(request.getParameter("keyw")!=null)    {
	flag4=true; keyw = request.getParameter("keyw");
}
if(request.getParameter("author")!=null)  {
	flag5=true; author = request.getParameter("author");
}
// 如果title不为空，则添加或修改记录
if(flag1 & flag2 & flag3 & flag4 & flag5 ) {
        // 执行插入操作
	    sql =  "update news set title='" + title ;
	    sql += "',content='" + content + "',keyw='" + keyw + "',author='";
	    sql += author + "' where id=" + id;
        conn.executeUpdate( sql );
		out.println("<hr>");
		out.println("<h2>新闻添加成功！</h2>");
		out.println("<hr>");
}else {
		out.println("<hr>");
        out.println("<h2>请输入正确的信息后再进行录入！</h2>");
		out.println("<hr>");
}
%>
<jsp:forward page="newsedit.jsp"/>
