Servlet 传输中文乱码解决方法
程序员文章站
2022-07-14 19:21:34
...
就一句话,而且要用于讲所要转换的变量之下:
name = new String(name.getBytes("iso-8859-1"),"utf-8");
整体代码:
package guigu;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
public class paramServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("THIS is paramServlet!");
String name = request.getParameter("username");
name = new String(name.getBytes("iso-8859-1"),"utf-8");
String password = request.getParameter("password");
String[] hobby = request.getParameterValues("hobby");
System.out.println("用户名:"+name+" 密码:"+password+" 兴趣爱好:"+ Arrays.asList(hobby));
}
}
结果截图:
大体截图:
上一篇: vim中文乱码解决方法
下一篇: Stata中文乱码顽疾解决方法