jsp请求servlet地址时返回的中文为乱码时
来源:互联网 发布:vue.js 手风琴菜单 编辑:程序博客网 时间:2024/06/09 15:01
简介
当jsp请求servlet地址时放回的中文为乱码,首先我数据库中的编码格式为utf-8,包括jsp,myeclipse,servlet,都设置了这个编码,菜鸟小编最终百度到解决办法,直接上代码。
jsp
package application.admin.servlet.cate;import java.io.*;import javax.servlet.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.*;import org.json.JSONArray;import application.admin.cate.Cate;import common.api.CommonApi;@WebServlet("/CateListServlet")public class CateListServlet extends HttpServlet { private String json_data; public void init() throws ServletException { } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Content-Type", "text/html; charset=UTF-8"); JSONArray book_cate_list; String user_id = request.getParameter("user_id"); String state = request.getParameter("state"); Cate cate = new Cate(); try { book_cate_list = cate.book_cate_list();//获取所有图书分类 int count_cate = cate.count_cate();//统计图书分类个数 json_data = CommonApi.return_json(book_cate_list,count_cate);//拼装返回数据 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } response.getOutputStream().write(json_data.getBytes("utf-8")); } public void destroy() { // 什么也不做 }}
servlet
package application.admin.servlet.cate;import java.io.*;import javax.servlet.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.*;import org.json.JSONArray;import application.admin.cate.Cate;import common.api.CommonApi;@WebServlet("/CateListServlet")public class CateListServlet extends HttpServlet { private String json_data; public void init() throws ServletException { } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Content-Type", "text/html; charset=UTF-8"); JSONArray book_cate_list; String user_id = request.getParameter("user_id"); String state = request.getParameter("state"); Cate cate = new Cate(); try { book_cate_list = cate.book_cate_list();//获取所有图书分类 int count_cate = cate.count_cate();//统计图书分类个数 json_data = CommonApi.return_json(book_cate_list,count_cate);//拼装返回数据 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } response.getOutputStream().write(json_data.getBytes("utf-8")); } public void destroy() { // 什么也不做 }}
阅读全文
0 0
- jsp请求servlet地址时返回的中文为乱码时
- servlet处理get请求时的中文乱码问题
- 解决LoadRunner请求返回中文为乱码的问题
- JSP/Servlet页面中文显示为乱码的解决方式
- JSP/Servlet页面中文显示为乱码的解决方式
- JSP/Servlet页面中文显示为乱码的解决方式
- JSP利用servlet上传文件时的中文乱码问题
- JSP利用servlet上传文件时的中文乱码问题
- JSP-Servlet的中文乱码
- jquery的 ajax返回值为中文时乱码解决方法
- jquery的 ajax返回值为中文时乱码解决方法
- jsp传参时若Url为中文时的乱码问题
- 【jsp】Servlet中请求乱码的问题
- JSP-Servlet中文乱码
- JSP/Servlet中文乱码问题的解决
- JSP和Servlet的中文乱码处理
- JSP与Servlet的中文乱码处理
- JSP和Servlet的中文乱码处理
- The form contains the following error: Fingerprint has already been taken
- LUOGU P2085 最小函数值
- 第n个丑数(java版)
- 语言常青树——C
- “智能”贪吃蛇
- jsp请求servlet地址时返回的中文为乱码时
- JavaScript
- Numpy基础教程 — 线性代数
- python简介
- 支付宝即时到账接口开发视频教程密码
- 冒泡排序Java实现
- JS的事件(2)--事件函数的取消/事件默认行为/键盘事件/鼠标滚轮事件
- java 13位时间戳,在前台转换为日期格式jq封装
- 获取一个字符串的所有子串