1.通过超链接的默认方式是GET。
2.通过表单的默认方式GET。
本以为两种方式处理的方式不一样,但是发现都一样!!!
so:
j1.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'j1.jsp' starting page</title>
</head>
<body>
<form action="j2.jsp">
<input type="text" name = "boy"/>
<input type="submit" />
</form>
</body>
</html>
j2.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<%
//request.setCharacterEncoding("utf-8");
String error = request.getParameter("boy");
byte[] b = error.getBytes("ISO-8859-1");
error = new String(b,"utf-8");
out.print(error);
%>
</body>
</html>
主要的核心在于:
String error = request.getParameter("boy");
byte[] b = error.getBytes("ISO-8859-1");
error = new String(b,"utf-8");//这里的第二个参数很关键!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
当action方式是post时候,iso-8859-1就无效,而是更简单的使用:
request.setCharacterEncoding(“utf-8”);直接搞定了~
超链接相当于 表单的get方式,一样用iso-8859-1可以解决它!