//add.jsp 添加信息页面 <% /*Cookie c[]=request.getCookies(); if(c==null) {response.sendRedirect("login.jsp");}*/ String userName=(String)session.getAttribute("admin"); if(userName==null) {response.sendRedirect("login.jsp");} out.println("Welcome, "+userName); request.setCharacterEncoding("big5");%> <%@ page contentType="text/html;charset=big5"%> <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"/> <script language="javascript"> function f1_submit(){ if(document.f1.title.value=="") { alert("Sorry, 信息沒有輸入") document.f1.title.focus() return false } else if(document.f1.types.value=="") { alert("Sorry, 必需輸入信息類型!") document.f1.types.focus() return false } } </script> </head> <style type="text/css"> <!-- .style2 { color: #FFFFFF; font-weight: bold; } .style3 {color: #FF0000} .style5 {color: #0080C0} --> </style> <form method="post" action="save.jsp" name="f1" LANGUAGE="javascript" onsubmit="return f1_submit()" > <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 name="title" type="text" size="70"></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="23"><span class="style5">鏈接地址</span></td> <td><input name="url" type="text" size="70"></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="28"><span class="style5">信息類型</span></td> <td><select name="types"> <option value="mobile phone">mobile phone</option> <option value="pc">pc</option> <option value="mp3">mp3</option> <option value="notebook">notebook</option> </select></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="26"><span class="style5">信息說明</span></td> <td><textarea name="content"></textarea></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="29"><span class="style5">信息大小</span></td> <td><input name="big" type="text" size="10"></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="27"><span class="style5">信息評價</span></td> <td><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 name="from1" type="text" size="64"></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="32"><span class="style5">相關地址</span></td> <td><input name="form_url" type="text" size="64"></td> </tr> <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <td height="46" colspan="2"><div align="center"> <input name="Submit" type="submit" id="Submit" value="確認" class="buttonface"/> <input type="reset" name="Reset" value="取消" class="buttonface"> </div></td> </tr> </table> </form> </html> //************************将添加的信息插入数据库:save.jsp <%@ include file="articleconn.jsp"%> <%@ page import="moonsoft.test.j2ee.news.*"%>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Big5"> <title>保存信息</title> </head> <body> </body> </html> <% 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); // decided the request contents if(vote1==null) { out.println("<script language=javascript> alert(''''錯誤提示:為做評價!'''');javascript:history.back();</script>"); } String time="2005-03-01 19:00:00"; boolean autoCommit=conn.getAutoCommit(); try{ PreparedStatement ps=conn.prepareStatement(queryDBTime); ResultSet rs=ps.executeQuery(); while(rs.next()) { time=rs.getString(1); } String insert=" insert into learning(article_id, types, title, url, content, big, vote, from1, form_url, date_and_time, hits) "+ " values(add_id_seq.NEXTVAL, ''''"+types+"'''', ''''"+title+"'''', ''''"+url+"'''', ''''"+content+"'''', ''''"+big+"'''', ''''"+vote+"'''', ''''"+from1+"'''', ''''"+form_url+"'''', ''''"+time+"'''', 1 ) " ; out.println(insert); ps=conn.prepareStatement(insert); int rs1=ps.executeUpdate(); if(rs1>0) { %> <head> <link rel="stylesheet&quo [1] [2] 下一页 [Web开发]JSP入门学习经验总结 [Sql Server]Sql精妙语句--各种求值函数 [网页制作]网页表格之---多个表格纵向排列 [网页制作]JavaScript另类用法--读取和写入cookie [网页制作]号称非常安全的上网工具---360安全浏览器介绍 [办公软件]信息技术教学篇---Word工具栏的显示、隐藏及四种菜… [操作系统]开始菜单---运行命令大总结 [操作系统]网络转载---64位操作系统与32位的区别 [操作系统]ldap:///(没有响应)Windows无法访问指定设备、路径… [网络技术]安全篇---交换机设置方法介绍
|