日期:2014-05-19  浏览次数:20755 次

关于JSP 、 Servlet中文乱码问题, 方法差不多试完了 还是不行- -!
JSP页面1:
<table border="1">
<%@page import="com.bookmanagersys.bean.Operator"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"
+request.getServerPort()+path+"/";
List<Operator> list=(List<Operator>)request.getAttribute("operatorlist");

%>
<table>
  <tr><th>用户名</th><th>密码</th><th>等级</th><th>操作</th></tr>
  <%
  for(int i=0;i<list.size();i++){
  Operator operator=list.get(i);
  %>
  <tr>
  <td><input type="text" name="name" value="<%=operator.getName()%>"></td>
  <td><input type="text" name="password" value="<%=operator.getPassword()%>"></td>
  <td><input type="text" name="level" value="<%=operator.getLevel()%>"></td>
  <td><a href="./GetOneUserServlet?name=<%=operator.getName()%>">修改用户</a>
  &nbsp;&nbsp;<a href="./DeleteUserServlet?name=<%=operator.getName()%>">删除用户</a></td>
  </tr>
  <%} %>
  <tr><td></td><td colspan="2"><a href="addOperator.jsp">添加用户</a></td><td><br></td></tr>
  </table>
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxx
GetOneUserServlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//response.setCharacterEncoding("utf-8");
OperatorService operatorService=new OperatorService();
System.out.println(request.getParameter("name"));
Operator operator=operatorService.findOne(request.getParameter("name"));
//request.getSession().putValue("updateoperator", operator);
//request.getSession().setAttribute("updateoperator", operator);
if (operator==null) {
System.out.println("operator==null");
}else {
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXX");
}
request.setAttribute("updateoperator", operator);
request.getRequestDispatcher("updateOperator.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doGet(request, response);

}如果修改的是JSP页面1中name为中文的记录在这里面的到的是乱码
xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
JSP页面2:
<form name="form" action="" method="post" >
  <table border="1">
  <tr>
  <td>用&nbsp;&nbsp;户名:</td>
  <td><input type="text" name="name" value="<%=operator.getName()%>"></td>
  </tr>
  <tr>
  <td>密&nbsp;&a