[java]代码库
package pm_cn.itcast.request;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RequestDemo4 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 获得 提交过的 请求 的 参数
// 就希望 如果 能够 手动的 指定 request的 编码 那么就可以 解决乱码了
String name = request.getParameter("name");
System.out.println(" name : " + name );
byte[] bb = name.getBytes("ISO8859-1");
String value = new String(bb,"UTF-8");
System.out.println(" 解决后的 value :" + value);
System.out.println("===============");
String encodedValue = URLEncoder.encode(name, "iso8859-1");
String value2 = URLDecoder.decode(encodedValue, "UTF-8");
System.out.println("value2 : " + value2);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}