创星网络[分享知识 传递快乐]

标题: JSP写文件代码 [打印本页]

作者: luinstein    时间: 2012-12-13 19:54
标题: JSP写文件代码
  1. <%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" errorPage="" %>


  2. <%@ page import="java.io.*" %>

  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5.   <head>
  6.    
  7.     <title></title>
  8. <meta http-equiv="pragma" content="no-cache">
  9. <meta http-equiv="cache-control" content="no-cache">
  10. <meta http-equiv="expires" content="0">   
  11. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  12. <meta http-equiv="description" content="This is my page">
  13. <!--
  14. <link rel="stylesheet" type="text/css" href="styles.css">
  15. -->
  16.     <link href="css/common_1.css" rel="stylesheet" type="text/css" />
  17.    <link rel="SHORTCUT ICON" href="../favicon.ico" />
  18.    
  19.    <style type="text/css">
  20. <!--
  21. .STYLE2 {font-size: 12px}
  22. -->
  23.    </style>
  24. </head>
  25.   
  26.   <body>

  27.       <%

  28.    String path_in = "";
  29.    String content = "";

  30.    path_in = request.getRealPath("/")+"admin"+File.separator+"manage_customer_details_edit.jsp";

  31.   
  32.    try
  33.    {
  34.    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter
  35.    (path_in)));
  36.    writer.println(
  37.    "<%"
  38.    +"@ page contentType=/"text/html; charset=gbk/" language=/"java/" import=/"java.sql.*/" errorPage=/"/" %"
  39.    +">");
  40.    writer.println("<%"+"@ page import=/"cn.com.cxweb.pc.db.databean/" %"+">");
  41.     writer.println("<%"+"@include file=/"const.jsp/"%"+">");

  42.    
  43.    
  44.    writer.close();
  45.    out.println("已经把内容写入到文档"+path_in);
  46.    }
  47.    catch(Exception e)
  48.    {
  49.    out.println(e);
  50.    e.printStackTrace();
  51.    }
  52.    
  53.    
  54.    %>
  55.      
  56.         
  57.    </body>
  58. </html>
复制代码
----------------
发现输出%>时,需要分开





欢迎光临 创星网络[分享知识 传递快乐] (http://bbs.cxweb.com.cn/) Powered by Discuz! X3