如果在登录界面跳转到时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);
}
}

最新文章

  1. $_SERVER 的用法
  2. ElasticSearch 入门笔记1
  3. (转)用JQuery实现Fix表头表格
  4. Spring3.0提供的表达式语言spel
  5. [poco] HttpRequest之post方法
  6. Visual Studio 2012的开发使用技巧
  7. Hexo + Github Pages 搭建个人博客
  8. 【转】TCHAR
  9. Linux如何在一个文件中写入内容
  10. 当面试官说 &ldquo;你还有什么问题想问的&rdquo; ,你该如何回答?
  11. Python&#160;多线程并发程序设计与分析
  12. Codeforces 1036C Classy Numbers 【DFS】
  13. seq_file学习(1)—— single_open
  14. Spring MVC (Java),强制页面不缓存
  15. 阅读OReilly.Web.Scraping.with.Python.2015.6笔记---找出网页中所有的href
  16. RISC与CISCCPU构架
  17. android 开发 实现一个带图片Image的ListView
  18. 配置HugePage
  19. 【论文笔记】多任务学习(Multi-Task Learning)
  20. Scipy

热门文章

  1. 解决com.mysql.jdbc.PacketTooBigException: Packet for query is too large
  2. Scala学习笔记——断言和单元测试
  3. SQLSVR 之 EXISTS
  4. 【代码审计】XYHCMS V3.5任意文件删除漏洞分析
  5. DLL断点调试
  6. 【zheng阅读系列】shiro权限管理
  7. android.DataBindingUtil
  8. day_5.20 py
  9. 使用 vm 加载文件中的数据到变量里面
  10. 网易云信&amp;七鱼市场总监姜菡钰:实战解读增长黑客在B端业务的运用