HTTPServlet请求中文参数处理办法

为了成功获取中文参数,需要做如下操作
1. login.html中加上

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


这句话的目的是告诉浏览器,等下发消息给服务器的时候,使用UTF-8编码

获取参数前:

request.setCharacterEncoding("UTF-8");
并且把这句话放在request.getParameter()之前

以上是使用UTF-8的方式获取中文呢。 也可以使用GBK。把所有的UTF-8替换为GBK即可。 GB2312同理。

返回中文的响应

在Servlet中,加上

response.setContentType("text/html; charset=UTF-8");

猜你喜欢

转载自blog.csdn.net/qq_38275824/article/details/81662461