为了成功获取中文参数,需要做如下操作
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");