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

如何解决 jsp网页之间 传递中文乱码 的问题
<%@ page language="java" contentType="text/html; charset=gb2312"
  pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<!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>编辑图书信息</title>
<style type="text/css">
<!--
.STYLE1 {
font-size: 36px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<% String strId = request.getParameter("id");//获取传过来的参数(网络上传输的只能是字符串)
Class.forName("com.mysql.jdbc.Driver");//java的反射
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123");
PreparedStatement ps =con.prepareStatement("select * from t_book where id=?");
ps.setInt(1,Integer.parseInt(strId));

ResultSet rs=ps.executeQuery();
if(rs.next()){
 %>
<form name="form1" method="post" action="bookSaveEdit.jsp">
<!-- 关键语句 -->
<input type="hidden" name="id" value="<%=rs.getInt("id") %>">
  <div align="center" class="STYLE1">编辑图书信息</div>
  <table width="300" height="120" border="1" align="center">

  <tr>
  <td width="74">书名:</td>
  <td width="210"><input name="name" type="text" id="name" value="<%=rs.getString("name") %>"></td>
  </tr>
  <tr>
  <td>出版社:</td>
  <td><input name="publish" type="text" id="publish" value="<%=rs.getString("publish") %>"></td>
  </tr>
  <tr>
  <td>价格:</td>
  <td><input name="price" type="text" id="price" value="<%=rs.getFloat("price") %>"></td>
  </tr>
  <tr>
  <td colspan="2" align="center"><input type="submit" name="Submit" value="确定修改">
  <input type="reset" name="Submit2" value="取消"></td>
  </tr>
  </table>
</form>
<%
}
con.close();
 %>
</body>
</html>






然后传到




<%@ page language="java" contentType="text/html; charset=gb2312"
  pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<!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>保存编辑</title>
</head>
<body>
<%
String strId = request.getParameter("id");
String name=request.getParameter("name");
String pub=new String(request.getParameter("publish").getBytes("ISO-8859-1"), "gb2312");
String strPr=request.getParameter("price");
float price=Float.parseFloat(str