JSP adds and saves data code

Source: Internet
Author: User

JSP Add and save data code
<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= ' News ' and bigname= ' investor Relations ' 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 (); Close Recordset object
Stmtarticle.close (); Close Statement Object
%>

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 ("The article title cannot be empty!") ");
return false;
}
if (document.form1.smallclassname.value== "")
{
Alert (Please specify the Sub column!) ");
return false;
}

if (editor1.gethtml () = = "") {
Alert ("article content cannot be empty!") ");
return false;
}

if (document.form1.content.value.length>6553600)
{
Alert ("The article content is too long to exceed the database limit (64K)!" It is suggested that the article be divided into several parts input. ");
return false;
}
return true;
}

</script>


<body>
<br/>
&nbsp; <a href= "hanye_manage.jsp" > Article Management </a> |&nbsp; <a href= "hanye_add.jsp" > Article add </a>

<%

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 (' News ', ' "+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 ' > article: [" + Title +] Add success </p> ");
}
Stmt_add.close ();
}

%>

<form id= "Form1" Name= "Form1" method= "Post" action= "" onsubmit= "return Form1_onsubmit ()" >
<table width= "750" border= "1" align= "Center" >
<tr>
&LT;TD align= "Right" > article title:</td>
<td><input name= "title" type= "text" id= "title" Size= "/></td>"
</tr>
<tr>
&LT;TD align= "Right" > Belong to the column:</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= ' news ' and bigname= ' industry knowledge ' 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= "" > Do not specify a small class </option>
<%
 statement stmtbc=conn.createstatement (Resultset.type_scroll_ SENSITIVE,RESULTSET.CONCUR_READ_ONLY);
 string sqlbc= "select * from Hl_smallclass WHERE modiname= ' News ' and bigname= ' industry knowledge ' 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 (); Close Recordset object
Stmtbc.close (); Close Statement Object
%>
</select>
</label> </td>
</tr>

<tr>
<TD align= "Right" > Source:</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> article content:</p>
<p></p>
<p>&middot; To change lines, press shift+enter&middot; Please press enter</p></td> for another paragraph
<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= "></IFRAME>"

</td>
</tr>
<tr>
&LT;TD align= "Right" > Time:</td>
<td><input name= "Timea" type= "text" value= "<%=nowTime%>" ></td>
</tr>
<tr>
&LT;TD align= "Right" > Upload picture:</td>
&LT;TD valign= "Top" ><input name= "img" type= "text" value= "" > <iframe name= "ad" frameborder=0 Height=20 scrolling=no src= '. /upload.htm ' ></iframe></td>
</tr>
<tr>
&LT;TD align= "Right" > is home picture:</td>
&LT;TD valign= "Top" ><p>
<label>
<input type= "Radio" name= "RadioGroup1" value= "yes" >
Is </label>
<label>
<input name= "RadioGroup1" type= "Radio" value= "No" checked= "checked" >
No </label>
</p> </td>
</tr>

<input type= "hidden" name= "Zhouze" value= "<%=session.getattribute" ("AdminName")%> "/>"
<tr>
<td>&nbsp;</td>
<td><input type= "Submit" name= "Submit" value= "Add" onmouseover= "return Form1_onsubmit ();" />
<input type= "reset" name= "reset" value= "reset"/></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
</body>
<%
Conn.close ();
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.