//edit.jsp,通过manage.jsp链接过来的修改信息页面 <%@ include file="articleconn.jsp"%> <% String id1=request.getParameter("id").trim(); session.setAttribute("id", id1); int id=Integer.parseInt(id1); String queryInfo=" select * from learning where article_id='"+id+"' "; String updateHits=" update learning set hits=hits+1 where article_id='"+id+"' "; boolean autoCommit=conn.getAutoCommit(); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=big5"> <title>修改信息</title> <!--meta name="GENERATOR" content="Microsoft FrontPage 4.0"--> <link rel="stylesheet" href="css/style.css"/> </head> <style type="text/css"> <!-- .style2 { color: #FFFFFF; font-weight: bold; } .style3 {color: #FF0000} .style5 {color: #0080C0} --> </style> <form method="post" action="saveEdit.jsp" ><% try{ conn.setAutoCommit(false); PreparedStatement ps=conn.prepareStatement(updateHits); int results=ps.executeUpdate(); if(results>0) {out.println();} conn.commit(); ps=conn.prepareStatement(queryInfo); ResultSet rs=ps.executeQuery(); while(rs.next()){ %> <table width="100%" border="1" cellspacing="1" cellpadding="1"> <tr bordercolor="#FFFFFF" bgcolor="#B5D85E"> <td height="24" colspan="2"><div align="center"><span class="style2">修 改 信 息</span></div></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td width="14%" height="24"><span class="style5">信息名稱</span></td> <td width="86%"><input type="text" name="title" value="<%=rs.getString("title")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="23"><span class="style5">鏈接地址</span></td> <td><input type="text" name="url" value="<%=rs.getString("url")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="28"><span class="style5">信息類型</span></td> <td><input type="text" name="types" value="<%=rs.getString("types")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="26"><span class="style5">信息說明</span></td> <td><input type="text" name="content" value="<%=rs.getString("content")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="29"><span class="style5">信息大小</span></td> <td><input type="text" name="big" value="<%=rs.getString("big")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="27"><span class="style5">信息評價</span></td> <td>目前信息評價<% String temp=rs.getString("vote"); //out.println(temp); int tempVotes=Integer.parseInt(temp); for(int i=0; i<tempVotes; i++){%><font color="red">★</font><%} %>重新選定評價<span class="style3"> <input name="vote" type="radio" value="1">★ <input name="vote" type="radio" value="2"> ★★ <input name="vote" type="radio" value="3" checked>★★★<input name="vote" type="radio" value="4"> ★★★★ <input name="vote" type="radio" value="5"> ★★★★★</span></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="24"><span class="style5">相關主頁</span></td> <td><input type="text" name="from1" value="<%=rs.getString("from1")%>" size=70></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="32"><span class="style5">相關地址</span></td> <td><input type="text" name="form_url" value="<%=rs.getString("form_url")%>" size=70> </td> </tr> <tr> </tr> </table> ID:<%=rs.getString("article_id")%> 點繫次數:<%=rs.getString("hits")%> 創建時間:<%=rs.getString("date_and_time")%> <% }} catch(SQLException se1) {se1.printStackTrace(); conn.rollback();} catch(NumberFormatException n1) {n1.printStackTrace(); throw n1; } finally{ conn.setAutoCommit(autoCommit); conn.close(); } %> <br><center> <input type="submit" value="確認修改" class="buttonface"/> <input type="reset" value="清除" class="buttonface"/></center> </form> </html> //************************************保存修改:saveEdit.jsp <%@ include file="articleconn.jsp"%> <%@ page import="moonsoft.test.j2ee.news.*"%> <% String title1=request.getParameter("title"); String url1=request.getParameter("url"); String content1=request.getParameter("content"); String types1=request.getParameter("types"); //String hits1=request.getParameter("hits"); String big1=request.getParameter("big"); String vote1=request.getParameter("vote"); String from1=request.getParameter("from1"); String form_url1=request.getParameter("form_url"); //String queryDBTime=" select to_char(systimestamp, 'YYYY-MM-DD HH24:MI:SS') from dual "; //filter special Character String types=FilterSpecial.filter(types1); String url=FilterSpecial.filter(url1); String content=FilterSpecial.filter(content1); String big=FilterSpecial.filter(big1); int vote=Integer.parseInt(vote1); String from=FilterSpecial.filter(from1); String form_url=FilterSpecial.filter(form_url1); String title=FilterSpecial.filter(title1); String id=(String)session.getAttribute("id"); //out.println(id); boolean autoCommit=conn.getAutoCommit(); String update=" update learning "+ " set title='"+title+"', url='"+url+"', types='"+types+"', content='"+content+"', big='"+big+"', vote='"+vote+"', form_url='"+form_url+"', from1='"+from+"' "+ " where article_id='"+id+"' "; //out.println(update); try{ conn.setAutoCommit(false); PreparedStatement ps=conn.prepareStatement(update); int result =ps.executeUpdate(); if(result>0){ %> <div align="center"> <p> </p><table border="1" cellspacing="0" width="50%" bgcolor="#F0F8FF" bordercolorlight="#000000" bordercolordark="#FFFFFF" align="center"> <tr> <td width="100%" bgcolor="#B5D85E" height="20"> <p align="center"><font color="#FFFFFF"><b>添加修改成功</b></font> </td> </tr> <tr> <td width="100%" height="177"> <table width="80%" border="0" cellspacing="0" cellpadding="2" align="center" bordercolorlight="#000000" bordercolordark="#FFFFFF"> <tr> <td>信息名稱為:<font color="#FF0000"><%=title%></font></td> <td>編號為:<font color="#FF0000"><%=id%></font></td> </tr> </table> <p align="center"> </p> <p align="center"><a href="manage.jsp">返回管理頁面</a><br> </p> </td> </tr> </table> </div> <% //response.sendRedirect("manage.jsp"); } conn.commit(); } catch(SQLException se1){se1.printStackTrace(); conn.rollback();} finally{ conn.setAutoCommit(autoCommit); conn.close();} %>
//**********************删除页面之一:提示要删除的信息delete.jsp <%@ include file="article.jsp"%> <% String id=request.getParameter("id"); String title=request.getParameter("title"); //out.println(title); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Big5"> <title>確認刪除</title> </head> <body> <div align="center"> <p> </p><table border="1" cellspacing="0" width="50%" bgcolor="#F0F8FF" bordercolorlight="#000000" bordercolordark="#FFFFFF" align="center"> <tr> <td width="100%" bgcolor="#B5D85E" height="20"> <p align="center"><font color="#FFFFFF"><b>刪除信息</b></font> </td> </tr> <tr> <td width="100%" height="177"> <table width="80%" border="0" cellspacing="0" cellpadding="2" align="center" bordercolorlight="#000000" bordercolordark="#FFFFFF"> <br><br> <tr> <td>確認刪除編號為:<font color="#FF0000"><%=id%></font> , 名稱為<font color="#FF0000"><%=title%></font>的信息嗎?</td> </tr> </table> <br><br> <p align="center"><a href="saveDelete.jsp?id=<%=id%>">是</a> <a href="manage.jsp">否</a></p> </td> </tr> </table> </div> </body> </html> //***************删除页面之二:saveDelete.jsp,删除成功后直接跳转到manage.jsp页面 <%@ include file="articleconn.jsp"%> <% String id=request.getParameter("id"); boolean autoCommit=conn.getAutoCommit(); String delete=" delete from learning where article_id="+id+" ";
try{ conn.setAutoCommit(false); PreparedStatement ps=conn.prepareStatement(delete); int rs=ps.executeUpdate(); if(rs>0) {response.sendRedirect("manage.jsp");} } catch(SQLException se1) {se1.printStackTrace(); conn.rollback();} finally {conn.setAutoCommit(autoCommit); conn.close();} %> 
|