editnewsok.jsp
上传用户:helenhuo66
上传日期:2007-06-01
资源大小:865k
文件大小:2k
源码类别:

百货/超市行业

开发平台:

Java

  1. <%@ page contentType="text/html;charset=GBK" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ include file="conn.jsp"%>
  3. <%!
  4. String encode(String str)
  5.  {
  6.     String result;
  7.     int l;
  8.     if(str=="")
  9. {
  10.        result="";
  11. }
  12.     else
  13.     {
  14.     l=str.length();
  15. char[] chr=new char[l];
  16. str.getChars(0,l,chr,0);
  17.     result="";
  18. int i;
  19. for(i=0;i<=l-1;i++)
  20.   {
  21.     
  22.                switch(chr[i])
  23.     {
  24.     
  25.            case '<':
  26.                 result=result+"&lt;";
  27. break;
  28.            case '>':
  29.                 result=result+"&gt;";
  30.    break;
  31.               case 10:
  32.                 result=result+"<br>";
  33.   break;
  34.   case 13:
  35.                 result=result+"<br>";
  36.   break;
  37.            case 34:
  38.                 result=result+"&quot;";
  39.    break;
  40.            case '&':
  41.                 result=result+"&amp;";
  42.    break;
  43.               case ' ':
  44.         result=result+"&nbsp;";
  45.   break;
  46.                
  47.           case 9:
  48.                 result=result+"    ";
  49.    break;
  50.            default:
  51.                 result=result+String.valueOf(chr[i]);
  52. }
  53.   } 
  54. }
  55.     return result;
  56.   }
  57.  
  58. %>
  59. <%
  60. int news_id=Integer.parseInt(request.getParameter("news_id"));
  61. String news_title=getStr((request.getParameter("news_title")).trim());
  62. String news_content=getStr(request.getParameter("news_content"));
  63. if(news_title=="" || news_content=="")
  64.         out.print("输入数据不能为空<br><a href=addnews.jsp>返回</a>");
  65.     else{
  66. String n_c=encode(news_content);
  67. sql="update news set news_title='"+news_title+"',news_content='"+n_c+"' where news_id="+news_id+"";
  68. mdb.executeUpdate(sql);
  69. out.print("新闻修改成功!<br><a href=delnews.jsp>返回</a>");
  70. mdb.Close();
  71. }
  72. %>