Servlet----------在使用doGet()和doPost()是如何处理中文乱码
2024-10-12 06:33:00
如果在登录界面跳转到时servlet中使用doGet()方法显示中文出现乱码时,可以添加这两行代码来解决,但这不是唯一的方法
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK")
如我的
package cn.servlet; import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class Login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GBK");//解决乱码
response.setContentType("text/html;charset=GBK");//解决乱码 String name=request.getParameter("login");
String password=request.getParameter("password");
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out.println("欢迎-- "+name+" --登录!"+"</br>");
out.print("你的登录密码是:"+password);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
最新文章
- $_SERVER 的用法
- ElasticSearch 入门笔记1
- (转)用JQuery实现Fix表头表格
- Spring3.0提供的表达式语言spel
- [poco] HttpRequest之post方法
- Visual Studio 2012的开发使用技巧
- Hexo + Github Pages 搭建个人博客
- 【转】TCHAR
- Linux如何在一个文件中写入内容
- 当面试官说 &ldquo;你还有什么问题想问的&rdquo; ,你该如何回答?
- Python&#160;多线程并发程序设计与分析
- Codeforces 1036C Classy Numbers 【DFS】
- seq_file学习(1)—— single_open
- Spring MVC (Java),强制页面不缓存
- 阅读OReilly.Web.Scraping.with.Python.2015.6笔记---找出网页中所有的href
- RISC与CISCCPU构架
- android 开发 实现一个带图片Image的ListView
- 配置HugePage
- 【论文笔记】多任务学习(Multi-Task Learning)
- Scipy
热门文章
- 解决com.mysql.jdbc.PacketTooBigException: Packet for query is too large
- Scala学习笔记——断言和单元测试
- SQLSVR 之 EXISTS
- 【代码审计】XYHCMS V3.5任意文件删除漏洞分析
- DLL断点调试
- 【zheng阅读系列】shiro权限管理
- android.DataBindingUtil
- day_5.20 py
- 使用 vm 加载文件中的数据到变量里面
- 网易云信&;七鱼市场总监姜菡钰:实战解读增长黑客在B端业务的运用