servlet 表单 获取的String 类型长度超过300字,调用的action类不执行,请问这是为什么?如果表单字数短,就能执行,没问题,这是为什么啊,String类型应该能放下300个汉字吧?!例如--------------------------------------------------------------------------------------
表单:
  
<form method="get" action="/servlet/insert">
<table>
<tr>
<td>标题:</td>
<td><input type="text" name="title" size="40"/></td>
</tr>
<tr>
<td align="top">内容:</td>
<td><textarea cols="50" rows="10" id="content" name="content"></textarea></td>
</tr>
<tr>
<td>标签</td>
<td><input type="text" name="tag" size="20"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form></form>-------------------------------------------------------------------------action 类:package main;import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class Insert extends HttpServlet { @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub


System.out.println("content0");

try
        {
System.out.println("content1");
String title=new String(req.getParameter("title").getBytes("ISO-8859-1"),"utf-8");//解决中文乱码
String content=new String(req.getParameter("content").getBytes("ISO-8859-1"),"utf-8");//解决中文乱码
String tag=new String(req.getParameter("tag").getBytes("ISO-8859-1"),"utf-8");//解决中文乱码
System.out.println("content2");
System.out.println(content);

         //连接SQLite的JDBC//         Class.forName("org.sqlite.JDBC");
//         
//         //建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之
//
//         Connection conn = DriverManager.getConnection("jdbc:sqlite://d:/sqlite3.db");
//         
//         Statement stat = conn.createStatement();
//         
//         System.out.println(content);
//         
//         stat.executeUpdate( "insert into notebook values('1111','"+title+"','"+content+"','"+tag+"')" );//创建一个表,两列         
    //     stat.executeUpdate( "insert into tbl1 values('ZhangSan',8000);" ); //插入数据//   stat.executeUpdate( "insert into tbl1 values('LiSi',7800);" );
//   stat.executeUpdate( "insert into tbl1 values('WangWu',5800);" );
//   stat.executeUpdate( "insert into tbl1 values('ZhaoLiu',9100);" );
 
        // ResultSet rs = stat.executeQuery("select * from tbl1;"); //查询数据//         while (rs.next()) { //将查询到的数据打印出来
//
//             System.out.print("name = " + rs.getString("name") + " "); //列属性一
//
//             System.out.println("salary = " + rs.getString("salary")); //列属性二
//
//         }
         
  //       rs.close();
         
         
         
         
 //        conn.close(); //结束数据库的连接        }
        catch( Exception e )
        {
         e.printStackTrace ( );
        }
} @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
}}
-------------------------------------------------------------------------------

解决方案 »

  1.   

    用stringBuffer吧!Java 技术交流群:58156559
      

  2.   

    get方法提交,对参数的长度是有限制的,提交的参数比较长的,用doPost方法提交,.....
      

  3.   

    比较长的数据应该放到post请求里
    你把方法写在dopost里试试的。
      

  4.   

    用post提交,get提交不仅长度受限,而且还可能出现乱码。
      

  5.   

    doGet对应action中的get方法 
    而doPost对应action中的post方法 
    doGet和doPost作用是相同的,只是处理不同的method 
    需要知道get和post的不同点: get和post是起的作用是相同的, 
    如果你以get提交那么数据会显示在你的地址栏中,你还可以在地址栏中 
    直接输入get取得变量对应的值,但是使用get提交的值有长度限制。 
    用post不存在这样的问题,耶没有长度限制. 
      

  6.   

    <form method="get" action="/servlet/insert">
    改成
    <form method="post" action="/servlet/insert">