首页 > 代码库 > Java Web中乱码问题

Java Web中乱码问题

response.setContentType("text/html;charset=UTF-8");

用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件

package cn.edu.aynu.rjxy.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class BServlet extends HttpServlet {    /*     * 乱码     * */    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        //设置编码为UTF-8格式        response.setContentType("text/html;charset=UTF-8");        //创建out对象        PrintWriter out = response.getWriter();        //输出语句        out.println("今天是9月21号");        //手动刷新        out.flush();        //关闭流        out.close();    }}

 

Java Web中乱码问题