jsp增加并保存数据代码
<script language="javascript">
var onecount;
subcat = new Array();
<%
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date currentTime = new java.util.Date();
String nowTime = formatter.format(currentTime);
int i=0;
Statement stmtArticle=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SqlArticle="Select * from hl_smallclass WHERE modiname='新闻' AND bigname='投资者关系' order by bigname desc";
ResultSet RsArticle=stmtArticle.executeQuery(SqlArticle);
while (RsArticle.next()) {
String smallname = RsArticle.getString("smallname");
%>
subcat[<%=i%>] = new Array("<%=smallname%>","<%=RsArticle.getString("bigname")%>","<%=smallname%>");
<%
i++;
}
RsArticle.close(); //关闭记录集对象
stmtArticle.close(); //关闭语句对象
%>
onecount=<%=i%>;
function changelocation(locationid)
{
document.form1.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form1.SmallClassName.options[document.form1.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function doChange(objText, objDrop){
if (!objDrop) return;
var str = objText.value;
var arr = str.split("|");
var nIndex = objDrop.selectedIndex;
objDrop.length=1;
for (var i=0; i<arr.length; i++){
objDrop.options[objDrop.length] = new Option(arr[i], arr[i]);
}
objDrop.selectedIndex = nIndex;
}
function form1_onsubmit()
{
if (document.form1.Title.value=="")
{
alert("文章标题不能为空!");
return false;
}
if (document.form1.SmallClassName.value=="")
{
alert("请指定子栏目!");
return false;
}
if (Editor1.getHTML()==""){
alert("文章内容不能为空!");
return false;
}
if (document.form1.Content.value.length>6553600)
{
alert("文章内容太长,超出了数据库的限制(64K)!建议将文章分成几部分录入。");
return false;
}
return true;
}
</script>
</head>
<body>
<br />
<a href="Hanye_Manage.jsp">文章管理</a> | <a href="Hanye_Add.jsp">文章添加</a>
<hr color="#0099FF" size="1" />
<%
if (request.getParameter("Title") !=null)
{
String Title=new String(request.getParameter("Title").getBytes("iso-8859-1"));
String BigClassName=new String(request.getParameter("BigClassName").getBytes("iso-8859-1"));
String SCName=new String(request.getParameter("SmallClassName").getBytes("iso-8859-1"));
String CopyFrom=new String(request.getParameter("CopyFrom").getBytes("iso-8859-1"));
String count=new String(request.getParameter("count").getBytes("iso-8859-1"));
String code=new String(request.getParameter("code").getBytes("iso-8859-1"));
String timea=new String(request.getParameter("timea").getBytes("iso-8859-1"));
String img=new String(request.getParameter("img").getBytes("iso-8859-1"));
String ok=new String(request.getParameter("RadioGroup1").getBytes("iso-8859-1"));
String Content=new String(request.getParameter("Content").getBytes("iso-8859-1"));
String zhouze=new String(request.getParameter("zhouze").getBytes("iso-8859-1"));
Statement stmt_ADD=conn.createStatement();
String Sql="insert into hl_news (modiname,bigname,smallname,title,content,times,sourc,count,user,code,img,ok) values ('新闻','"+BigClassName+"','"+SCName+"','"+Title+"','"+Content+"','"+timea+"','"+ CopyFrom+"','"+count+"','"+zhouze+"','"+code+"','"+img+"','"+ok+"')";
int add1=stmt_ADD.executeUpdate(Sql);
if (add1>0){
out.print("<p align='center'>文章:["+ Title +"] 添加成功</p>");
}
stmt_ADD.close();
}
%>
<form id="form1" name="form1" method="post" action="" onsubmit="return form1_onsubmit()">
<table width="750" border="1" align="center">
<tr>
<td align="right">文章标题:</td>
<td><input name="Title" type="text" id="Title" size="40" /></td>
</tr>
<tr>
<td align="right">所属栏目:</td>
<td><span class="STYLE1">
<label>
<%Statement stmt_ArticleClass=conn.createStatement();
//String SqlArticleClass="Select * from tArticleClass where fParentID=0";
String SqlArticleClass="Select * from hl_bigclass where modiname='新闻' AND bigname='行业知识' order by id asc ";
ResultSet RsArticleClass=stmt_ArticleClass.executeQuery(SqlArticleClass);
%>
<select name="BigClassName" onChange="changelocation(document.form1.BigClassName.options[document.form1.BigClassName.selectedIndex].value)">
<%
while (RsArticleClass.next())
{
String ArticleClass_ClassID=RsArticleClass.getString("bigname");
%>
<option value="<%=ArticleClass_ClassID%>"><%=ArticleClass_ClassID%></option>
<%
}
%>
</select>
</label>
</span>
<%
RsArticleClass.close();
stmt_ArticleClass.close();
%> <label>
<select name="SmallClassName">
<option value="">不指定小类</option>
<%
Statement stmtbc=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String Sqlbc="Select * from hl_smallclass WHERE modiname='新闻' AND bigname='行业知识' order by bigname desc";
ResultSet Rsbc=stmtbc.executeQuery(Sqlbc);
while (Rsbc.next()) {
String smallnamebc = Rsbc.getString("smallname");
%>
<option value="<%=smallnamebc%>"><%=smallnamebc%></option>
<%
i++;
}
Rsbc.close(); //关闭记录集对象
stmtbc.close(); //关闭语句对象
%>
</select>
</label> </td>
</tr>
<tr>
<td align="right">来源:</td>
<td><input name="CopyFrom" type="text" id="CopyFrom" /></td>
</tr>
<input name="count" id="count" type="hidden" value="0">
<input name="code" type="hidden" id="code" value="0" >
<tr>
<td valign="top" align="right"><p>文章内容:</p>
<p></p>
<p>· 换行请按Shift+Enter· 另起一段请按Enter</p></td>
<td>
<textarea name="Content" style="display:none"></textarea>
<IFRAME ID="Editor1" src="../inc/Editor/eWebEditor.jsp?id=Content&style=standard&originalfilename=d_originalfilename&savefilename=d_savefilename&SavePathFileName=SavePicPathFileName" frameborder="0" scrolling="no" width="650" height="350"></IFRAME>
</td>
</tr>
<tr>
<td align="right">时间:</td>
<td><input name="timea" type="text" value="<%=nowTime%>"></td>
</tr>
<tr>
<td align="right">上传图片:</td>
<td valign="top"><input name="img" type="text" value=""> <iframe name="ad" frameborder=0 width=60% height=20 scrolling=no src='../upload.htm'></iframe></td>
</tr>
<tr>
<td align="right">是否首页图片:</td>
<td valign="top"><p>
<label>
<input type="radio" name="RadioGroup1" value="yes">
是</label>
<label>
<input name="RadioGroup1" type="radio" value="no" checked="checked">
否</label>
</p> </td>
</tr>
<input type="hidden" name="zhouze" value="<%=session.getAttribute("AdminName")%>" />
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="添加" onmouseover="return form1_onsubmit();"/>
<input type="reset" name="Reset" value="重置" /></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
<%
conn.close();
%>