日期:2014-05-17  浏览次数:20650 次

jsp传参存入数据库内参数值乱码
最开始碰到jsp之间传参乱码,后来解决了。但是看传到数据库内的值,居然也是乱码,并且各种网上方法都用了,还是不行,求解决。
这注册页面
---------------------------------------
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
  <head>
<title>注册页面</title>
     </head>
  <body>
        <form action="Register.jsp" method="post">
    <table align="center">
    <tr><td colspan="2">用户注册</td></tr>
    <tr><td>帐 号:</td><td><input type="text" name="username"/></td></tr>
    <tr><td>密 码:</td><td><input type="text" name="userpassword"/></td></tr>
    <tr><td colspan="2"><input type="submit"value="注册">
    <input type="reset"value="重置"></td></tr></table>
    </form>
  </body>
</html>

---------------------------------------
传参页面
---------------------------------------
<%@ page language="java"  contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*"%>


<html>
  <head>
  
    
    <title>注册</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>
   <%request.setCharacterEncoding("gb2312");
   String reqUsername=(String)request.getParameter("username");
     System.out.println(reqUsername);
     String reqPassword=(String)request.getParameter("userpassword");
     System.out.println(reqPassword); %>
    <%
    String url="jdbc:mysql://localhost:3306/javaweb";
    String user="root";
    String password="123456";
    Connection conn=null;
    PreparedStatement pstmt=null;
    try{
     Class.forName("com.mysql.jdbc.Driver");
     conn=DriverManager.getConnection(url,user,password);
     }
     catch(ClassNotFoundException e){
     out.println("找不到驱动类");
     }
     catch(SQLException e){
     out.println("无法连接MYSQL");}
     try{
    
&nbs