servlet编码乱码问题
2024-10-21 06:37:12
继承HttpServlet
重写doGet(HttpServletRequest req,HttpServletResponse resp),doPost()方法
post提交时:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//post方法:告诉servlet如何去处理文字编码,输出
response.setCharacterEncoding("utf-8");
//告诉浏览器如何处理编码
response.setContentType("text/html;charset=tf-8");
}
Get方法
继承extends HttpServletRequestWrapper
重写getParameter()方法
@Override
public String getParameter(String name) {
String value=request.getParameter(name);
String method=request.getMethod();
if("get".equalsIgnoreCase(method)){
try {
value=new String(value.getBytes("iso-8859-1"),"utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return value;
}
最新文章
- 简历生成平台项目开发-STEP2问卷调查结果统计分析
- Spark JdbcRDD 简单使用
- Python中通过cx_Oracle访问数据库遇到的问题总结
- 一个有趣的IE内核检测网站
- div里面的内容超出自身高度时,显示省略号
- Quartz中时间表达式的设置-----corn表达式
- Java语言定义的线程状态分析
- ThinkAdmin for PHP后台管理系统
- lr_场景设计之知识点-集合点、loadgenerator
- 『Python CoolBook』Cython_高效数组操作
- 岭回归、LASSO与LAR的几何意义
- redis 的简单用法
- Python2.7-collections
- Sprint计划会议内容
- CentOS安装SVN客户端
- Python - matplotlib 数据可视化
- 你在AutoHotKey面前居然敢比调音量 - imsoft.cnblogs
- [Asp.net]Calendar+JqueryUi实现日程管理——添加日程
- webservice和wcf和web.api简单介绍
- Blue Bird