表单提交显示乱码问题
response.setContentType("text/html;charset=gbk");request.setCharacterEncoding("gbk");
我已经加入了这两句代码还是出现乱码呢?
servlet 的代码如下:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gbk");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gbk");
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print("主题:");
out.print(request.getParameter("title")+"<br>");
out.println("内容:"+request.getParameter("editor"));
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
静态页面 fckeditor.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>fckeditor.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="/fckeditordemo/fckeditor/fckeditor.js"></script>
</head>
<body>
<form name="form3" action="/fckeditordemo/servlet/FCKeditorServlet">
主题:<input type="text" name="title"><br>
内容:
<script type="text/javascript">
var editor=new FCKeditor('editor');
editor.BasePath='/fckeditordemo/fckeditor/';
editor.Height=200;
editor.ToolbarSet='Default'; // Basic
editor.Create();
</script>
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
浏览器显示如下:
主题:??????
内容:
????????????