<%@ page language="java" pageEncoding="UTF-8"%>
< !-- 告诉浏览器该jsp格式为utf-8,此时注意网页本身(右击->properties)的编码是否为utf-8 -->
在head内加入:
< meta http-equiv="Content-Type" content="text/html; charset=utf-8">
对于get请求:
String name2 = new String(name.getBytes("iso-8859-1"),"UTF-8");
对于post请求
request.setCharacterEncoding("utf-8");//对于post方法有效,对get无效.一定要放在解析的第一行,否则不行。
String name = request.getParameter("name");
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>使用 GET 方法读取数据</h1>
<ul>
<li><p><b>站点名:</b>
<%
String name =request.getParameter("name");
String name2 = new String(name.getBytes("iso-8859-1"),"UTF-8");
%>
<%= name2%>
</p></li>
<li><p><b>网址:</b>
<%= request.getParameter("url")%>
</p></li>
</ul>
</body>
</html>
输出:
image.png
网友评论