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 }
  • 相关阅读:
    软件测试流程
    Python2 RF(3.0.4)与Python3 RF(3.1.2)区别
    Ubuntu Install RobotFramework with Python3
    Beta测试与Alpha测试有什么区别
    网络协议,如TCP/UDP的区别?
    缺陷相关知识
    linux_machine-id
    monkey自定义脚本实践
    Monkey事件
    Linux虚拟机fdisk分区
  • 原文地址:https://www.cnblogs.com/tdcqma/p/4756800.html
Copyright © 2011-2022 走看看