1 if(username.equals("") || password.euqals("")){
2 msg = "用户名密码不能为空";
3 String encodeMsg = java.net.URLEncoder.encode(msg, "GBK"); // URLEncoder参数进行转码,地址栏参数为16进制码
4 String url = "http://127.0.0.1:8080/Jsp_Servlet_JavaBean_01/index.jsp?error="+encodeMsg;
5 response.sendRedirect(url);
6 }
-
- jsp页面pageEncoding设置为GBK,用getBytes方法使字符集形式转换成ISO-8859-1
1 <%
2 String msg = request.getParameter("error");
3 if(msg != null){
4 msg = new String(msg.getBytes("ISO-8859-1"),"utf-8");
5 out.print(msg);
6 }
7 %>
-
- jsp向servlet传中文参数,一般使用POST方式
1 request.setCharacterEncoding("GBK");