首先是一个模板文件template.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head><body>
  <body>   
  <table   width="500"   border="0"   align="center"   cellpadding="0"   cellspacing="2">   
      <tr>     
          <td   align="center">###title###</td>   
      </tr>   
      <tr>     
          <td   align="center">author:###author###&nbsp;&nbsp;</td>   
      </tr>   
      <tr>   
          <td>###content###   
    </td>   
      
      </tr>   
    
  </table>   
</body>
</html>这个是自己写的一个JAVA类:
package DB;
import java.io.*;
import java.util.*;public class AutoCreate {
//    private String   title= null;   
//    private String   content= null;   
//    private String   editer= null;   
    private String   filePath   = null;   
    
    public AutoCreate()
    {
    
    }
    
    public String CreateFile(String path, String title, String content, String editer)
    {
     filePath = path + "html/template.htm";   
     String   templateContent="";
     try{
            FileInputStream fileinputstream = new FileInputStream(filePath);//读取模块文件   
            int lenght = fileinputstream.available();   
            byte bytes[] = new byte[lenght];   
            fileinputstream.read(bytes);   
            templateContent = new String(bytes);   
            fileinputstream.close();    
     }catch(Exception ex)
     {
     System.out.println(ex.getMessage());
     }        templateContent=templateContent.replaceAll("###title###",title);   
        templateContent=templateContent.replaceAll("###content###",content);   
        templateContent=templateContent.replaceAll("###author###",editer);//替换掉模块中相应的地方           //      根据时间得文件名   
        Calendar calendar = Calendar.getInstance();   
        String filename = "html/" + String.valueOf(calendar.getTimeInMillis()) +".html";   
        filename =  path + filename;//生成的html文件保存路径   
        
        try{
            FileOutputStream fileoutputstream = new FileOutputStream(filename);//建立文件输出流   
            byte tag_bytes[] =  templateContent.getBytes();   
            fileoutputstream.write(tag_bytes);   
            fileoutputstream.close();       
        }catch(Exception ex)
        {
         System.out.println(ex.getMessage());
        }
        return filename;
    }
    
}
我用的都是“utf-8”现在我在jsp文件里面显示时是正常的,但是生成的静态页面里面显示时却是乱码。。个人觉得可能是数据读入的时候可能和哪个地方的编码不合所以才出现乱码。。请高手报指点啊!!!

解决方案 »

  1.   

    ResultSet rs = mes.SelectMessages("first");
         if(rs !=null && rs.next())
         {
        %>
         <table width="752" border="0" cellspacing="0" cellpadding="0">
        <tr>
           <td width="300">自动生成条目</td>
         </tr>
         <%
         do
         {
         String CreateFileName = m_page.CreateFile(request.getRealPath("/"), rs.getString("messagetitle"), rs.getString("content"), rs.getString("username"));
         %>
                <tr>
            <td><a href= <%= CreateFileName%> target="_blank"><%=rs.getString("content") %></a></td>
               </tr>
         <%}while(rs.next());
         }%>JSP文件中调用的代码。
      

  2.   

    你生成的html页面里为<meta http-equiv="Content-Type" content="text/html; charset=utf-8">所以中文不能正常显示