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

JSP表单提交数据到MySQL
我这个代码的功能是进入add_text.jsp里面输入内容提交,然后讲提交的内容写入MySQL,请问各位大大为什么这个实现操作[color=#FF0000]只有提交数字才能写入数据库提交英文和中文都不能写入到MySQL里面。SQL里面定义的是两个vachar类型的属性,编码格式都是GBK。[/color]

add_text.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <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">
-->
    <script type="text/javascript"">
    function validate()
    {
    var Tname = document.forms[0].Tname.value;
    var Ttext = document.forms[0].Ttext.value;
     //document.getElementById("form").submit();
    }
    </script>
  </head>
  
  <body>
  <br>
  <center>
  <h2>添加留言文本</h2><hr>
 <form action="insert.jsp" method="post" id="form" onSubmit="return validate()" >
<h4>  昵称:<input type="text" name="Tname" class="{required:true}"></input><br></h4>
<h4>  留言内容:<input type="text" name="Ttext"></input><br></h4>
 <input type="submit" value="提交"/>
  </form>
  <a href="">查询所有留言</a>
  </center>
  </body>
</html>


insert.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <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"