首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

生成静态页面时出现乱码的有关问题!

2012-01-24 
生成静态页面时出现乱码的问题!!首先是一个模板文件template.htm!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01

生成静态页面时出现乱码的问题!!
首先是一个模板文件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文件里面显示时是正常的,但是生成的静态页面里面显示时却是乱码。。个人觉得可能是数据读入的时候可能和哪个地方的编码不合所以才出现乱码。。请高手报指点啊!!!

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

热点排行