addnews.jsp
上传用户:szlmxq
上传日期:2014-01-31
资源大小:740k
文件大小:3k
源码类别:

Applet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=GBK" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ include file="conn.jsp"%>
  3. <%
  4. if(session.getAttribute("admin_name")==null){
  5. ;}else{
  6. %>
  7. <head>
  8. <style type=text/css>
  9. td  { font:normal 12px 宋体; }
  10. img  { vertical-align:bottom; border:0px; }
  11. a  { font:normal 12px 宋体; color:#000000; text-decoration:none; }
  12. a:hover  { color:#428EFF;text-decoration:underline; }
  13. .sec_menu  { border-left:1px solid white; border-right:1px solid white; border-bottom:1px solid white; overflow:hidden; background:#D6DFF7; }
  14. .menu_title  { }
  15. .menu_title span  { position:relative; top:2px; left:8px; color:#215DC6; font-weight:bold; }
  16. .menu_title2  { }
  17. .menu_title2 span  { position:relative; top:2px; left:8px; color:#428EFF; font-weight:bold; }
  18. </style>
  19. </head>
  20. <%!
  21. String encode(String str)
  22.  {
  23.     String result;
  24.     int l;
  25.     if(str=="")
  26. {
  27.        result="";
  28. }
  29.     else
  30.     {
  31.     l=str.length();
  32. char[] chr=new char[l];
  33. str.getChars(0,l,chr,0);
  34.     result="";
  35. int i;
  36. for(i=0;i<=l-1;i++)
  37.   {
  38.     
  39.                switch(chr[i])
  40.     {
  41.     
  42.            case '<':
  43.                 result=result+"&lt;";
  44. break;
  45.            case '>':
  46.                 result=result+"&gt;";
  47.    break;
  48.               case 10:
  49.                 result=result+"<br>";
  50.   break;
  51.   case 13:
  52.                 result=result+"<br>";
  53.   break;
  54.            case 34:
  55.                 result=result+"&quot;";
  56.    break;
  57.            case '&':
  58.                 result=result+"&amp;";
  59.    break;
  60.               case ' ':
  61.         result=result+"&nbsp;";
  62.   break;
  63.                
  64.           case 9:
  65.                 result=result+"    ";
  66.    break;
  67.            default:
  68.                 result=result+String.valueOf(chr[i]);
  69. }
  70.   } 
  71. }
  72.     return result;
  73.   }
  74.  
  75. %>
  76. <%
  77. String action=request.getParameter("action");
  78. if(action==null)
  79. action="notsave";
  80. if(action.equals("save")){
  81.    
  82.     String news_title=getStr((request.getParameter("news_title")).trim());
  83.     String news_content=getStr(request.getParameter("news_content"));
  84.     if(news_title=="" || news_content=="")
  85.         out.print("输入数据不能为空<br><a href=addnews.jsp>返回</a>");
  86.     else{
  87.         String n_c=encode(news_content);
  88.         
  89. sql="insert into news(news_title,news_content) values('"+news_title+"','"+n_c+"')";
  90.         mdb.executeInsert(sql);
  91.         out.print("新闻添加完成<br><a href=addnews.jsp>返回</a>");
  92.     }
  93. }else{%>
  94. <body style="background-color: #808080">
  95. <table border="0" width="100%" cellspacing="1">
  96.   <tr>
  97.     <td width="100%">
  98.       <form method="POST" action="addnews.jsp?action=save">
  99.         <table border="0" width="100%" cellspacing="1">
  100.           <tr>
  101.             <td width="100%"> </td>
  102.           </tr>
  103.           <tr>
  104.             <td width="100%"><font color="#FFFFFF">新闻标题</font><input type="text" name="news_title" size="20" class=input></td>
  105.           </tr>
  106.           <tr>
  107.             <td width="100%"><font color="#FFFFFF">新闻内容</font></td>
  108.           </tr>
  109.           <tr>
  110.             <td width="100%"><textarea rows="14" name="news_content" cols="79" class=input></textarea></td>
  111.           </tr>
  112.         </table>
  113.         <p><input type="submit" value="提交" name="B1" class=input><input type="reset" value="全部重写" name="B2" class=input></p>
  114.       </form>
  115.       <p> </td>
  116.   </tr>
  117. </table>
  118. <%mdb.Close();}
  119. }
  120. %>