zoukankan      html  css  js  c++  java
  • Servlet的response输出到页面时乱码的解决方法

     1 package com.mhb;
     2 import java.io.IOException;
     3 import java.io.PrintWriter;
     4 
     5 import javax.servlet.ServletException;
     6 import javax.servlet.http.HttpServlet;
     7 import javax.servlet.http.HttpServletRequest;
     8 import javax.servlet.http.HttpServletResponse;
     9 
    10 
    11 public class MyServlet extends HttpServlet {
    12 
    13 public void init() throws ServletException {
    14 }
    15 
    16 public void doGet(HttpServletRequest request, HttpServletResponse response)
    17 throws ServletException, IOException {
    18 //解决乱码方法一:response.setCharacterEncoding("UTF-8");此种方法无效的时候请尝试下一行(19行)的方法。 
    19 response.setHeader("content-type","text/html;charset=UTF-8");
    20 //获得输出流 21 PrintWriter out = response.getWriter(); 22 //输出到网页上 23 out.print("<font color='red'>这是我的第一个示例</font><br>testtest"); 24 } 25 26 public void doPost(HttpServletRequest request, HttpServletResponse response) 27 throws ServletException, IOException { 28 } 29 30 public void destroy() { 31 super.destroy(); 32 } 33 }
  • 相关阅读:
    python连接字符串的几种方法--转子(香草拿铁的园子)
    winform属性
    C# Timer
    SQL基础
    SQL 基础
    File类 ReadAllBytes() ReadAllLines() ReadAllText()
    学习C#20天有感
    装箱和拆箱
    机器学习基础:朴素贝叶斯小结
    分类问题样本不均衡问题
  • 原文地址:https://www.cnblogs.com/tdcqma/p/4756800.html
Copyright © 2011-2022 走看看