问题描述
<%@pagecontentType="text/html;charset=UTF-8"%><html><head><title>用户注册</title></head><body><bodybackground="image/04.jpg"><center><br><br><br><h1>用户注册界面</h1><br><br><br><formname="form1"onsubmit="returncheck()"method="post"action="registerCheck.jsp">用户名:<inputname="username"type="text"><br><br>密码:<inputname="password"type="password"><br><br>确认密码:<inputtype="password"name="password1"><br><br>年龄:<inputname="age"type="text"><br><br>性别:<inputname="sex"type="radio"value="男"checked>男<inputname="sex"type="radio"value="女">女<br><br>教育程度:<selectname="education"size=1><optionvalue="">请选择</option><optionvalue="硕士">研究生</option><optionvalue="本科">本科</option><optionvalue="专科">专科</option><optionvalue="中专">中专</option><optionvalue="高中">高中</option></select><br><br><inputtype="submit"name="Submit"value="提交"><inputtype="reset"name="Reset"value="重填"></form></body></html><scripttype="text/javascript">functioncheck(){if(form1.username.value==""){alert("请输入用户名!!!");form1.username.focus();returnfalse;}if(form1.password.value==""){alert("请输入密码!!!");form1.password.focus();returnfalse;}if(form1.password.value!=form1.password1.value){alert("两次密码不一致,请重新输入!");form1.password.focus();returnfalse;}}</SCRIPT><%@pagecontentType="text/html;charset=UTF-8"%><%@pageimport="java.sql.*"%><html><head><title>数据更新后的页面</title></head><bodybackground="images/2.jpg"><center><h5><%=request.getParameter("username")%>你好,恭喜您注册成功!</h5></center><%Stringna=request.getParameter("username");session.setAttribute("username",na);%><center><br><br><%Stringusername=request.getParameter("username");byteb1[]=username.getBytes("UTF-8");username=newString(b1);Stringpassward=request.getParameter("password");Stringsex=request.getParameter("sex");byteb2[]=sex.getBytes("UTF-8");sex=newString(b2);Stringphone=request.getParameter("phone");Stringeducation=request.getParameter("education");byteb3[]=education.getBytes("UTF-8");education=newString(b3);request.setCharacterEncoding("UTF-8");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connectionconn=DriverManager.getConnection("jdbc:odbc:ts","sa","");Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSetrs=null;Stringsql="insertintouserinfovalues('"+username+"','"+passward+"','"+sex+"','"+phone+"','"+education+"')";inti=stmt.executeUpdate(sql);if(i!=0){stmt.close();conn.close();out.println("<h2>更新成功!</h2>");out.println("<h2>2秒钟后,自动跳转到图书馆主页!</h2>");response.setHeader("Refresh","2;URL=index1.jsp");}else{stmt.close();conn.close();out.println("<h2>更新失败!!!</h2>");%><ahref="welcome.jsp">返回</a>登录页面<%}%></center></body></html>
解决方案
解决方案二:
数据库编码是UTF-8吗?你再后台处理的地方输出一下接收到的字符串,看看前台传递的有没有乱码
解决方案三:
数据库编码格式错误!如果你确定应用端传进去时正确的!
解决方案四:
就跟楼上说的,确定自己数据库是否utf-8编码然后在自己后台system.out.println一下,看看数据传到后台时是不是已经乱码了
解决方案五:
楼上正解,要么在后台乱了,要么存数据库时乱了