jsp增加並儲存資料代碼

來源:互聯網
上載者:User

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 />
&nbsp; <a href="Hanye_Manage.jsp">文章管理</a> |&nbsp; <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>&middot; 換行請按Shift+Enter&middot; 另起一段請按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>&nbsp;</td>
      <td><input type="submit" name="Submit" value="添加" onmouseover="return form1_onsubmit();"/>
      <input type="reset" name="Reset" value="重設" /></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>
<%
conn.close();
%>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.