jsp提交后中文变乱码
提交前是这样的
提交后是这样的
我的代码是这样的
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%@page import="Info.StudentInfo"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'queryStudent.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="/FirstWeb/StudentSer" method="post">
关键字: <input type="text" name="S_name">
<input type="submit" value="查找">
<input type="hidden" name="statue" value="queryStudent">
<br>
</form>
<%
ArrayList<StudentInfo> students=(ArrayList)request.getAttribute("students");
if(students!=null){
out.println(students.size());
out.println("的手术费是刚刚vvvvddd");
System.out.println("各方各个各个");
}
%>
</body>
</html>
该怎么改呢?请大家帮帮忙哦!
------解决方案--------------------你提交后的那个page为何不指定编码呢
------解决方案--------------------把各种编码统一为UTF-8
------解决方案--------------------request.setCharacterEncoding("utf-8");
------解决方案--------------------在输出前加response.setcontentType("text/html;charset=utf-8");
------解决方案--------------------在StudentSer里
request.setCharacterEncoding("utf-8");
或者加一个统一编码格式的过滤器。。。
------解决方案--------------------HTML的meta里面指定
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
------解决方案--------------------你是返回到本页面的吧,servlet检查下,还有就是如果不是本页面的话,跳转的下个页面编码为utf-8,或者用struts的话,可以在struts-config.xml文件中加<constant name="struts.i18n.encoding" value="utf-8"/>,或者自己定义一个拦截器,在每个请求到来的时候,request.setcharcterEncoding("utf-8");response.setcharcterEncoding("utf-8");你试试