0

I use myeclipse development software, the default encoding is utf-8, when I created JSP in java, there is a Chinese chaos phenomenon. I have been working back and forth for a long time and have not solved this problem. Can someone help me? After the successful establishment of jsp, the Chinese displayed inside becomes garbled.

public  void CreatHtml(String filePath){


        StringBuilder stringHtml = new StringBuilder();


        PrintStream printStream =null;

       try {
       printStream = new PrintStream(new FileOutputStream(filePath),true,"UTF-8");
} catch (UnsupportedEncodingException e) {
      e.printStackTrace();
}      catch (FileNotFoundException e) {
      e.printStackTrace();
}


        stringHtml.append("<html><head>");
        stringHtml.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
        stringHtml.append("<title>测试报告文档</title>");
        stringHtml.append("</head>");
        stringHtml.append("<body>");

        stringHtml.append("<h1>简单快速用Java动态生成jsp/html页面</h1>");
        stringHtml.append("</body></html>");
        try{

            printStream.println(stringHtml.toString());
        }catch (Exception e) {
            e.printStackTrace();
        }
    }



        public String execute(){


        String imgname =UUID.randomUUID().toString()+".jsp";
        System.out.println(imgname);

        String filePath = "d:\\MyEclipseWork\\gxAppWebServer\\WebRoot\\"+imgname;

        CreatHtml(filePath);


        return SUCCESS;
    }
weiwei
  • 1
  • 1

1 Answers1

2

There is an issue with your meta tag. Please replace your meta tag with below :

<meta charset="utf-8"> 
Abhijeet
  • 4,069
  • 1
  • 22
  • 38