zoukankan      html  css  js  c++  java
  • JZTK项目 驾照题库项目servlet层得到的json字符串在浏览器中 汉字部分出现问号?无法正常显示的解决方法

    servlet层中的代码如下:

    package com.swift.jztk.servlet;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.swift.jztk.biz.IQuestionBiz;
    import com.swift.jztk.biz.QuestionBizImpl;
    
    @WebServlet("/getQuestions")
    public class GetQuestions extends HttpServlet {
        private static final long serialVersionUID = 1L;
        IQuestionBiz biz = new QuestionBizImpl();
    
        public GetQuestions() {
            super();
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.getWriter().append("Served at: ").append(request.getContextPath());
            String testType = request.getParameter("testType");
            String json = biz.getQuestions(testType);
            response.getWriter().println(json);
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
        }
    
    }

    在get方法中增加设置服务器端和浏览器端的代码解析方式为utf-8

            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
    成功解决


  • 相关阅读:
    windows phone 自动隐藏的Popup from http://www.cnblogs.com/LoveJenny/archive/2011/07/14/2105869.html
    Linq update
    Windows Phone 7 MVVM模式数据绑定和传递参数 from:http://www.cnblogs.com/linzheng/archive/2011/03/27/1997086.html
    web 常见攻击与防护
    SFSA
    HDU 3530
    一笔话问题
    学习技巧
    练题宝典
    雪花
  • 原文地址:https://www.cnblogs.com/qingyundian/p/7622752.html
Copyright © 2011-2022 走看看