你的js写对了么你后台是否使用的是 doPost跳转的?

解决方案 »

  1.   

    form采用post方法,在你的servlet中应该有继承自httpservlet的doPost()方法,获取浏览器的数据。register()方法是从doPost中调用的吗?
      

  2.   

    一个简单的servlet,你里面doGet方法有没有调regist方法,直接断点调试01.import java.io.IOException;  
    02.import javax.servlet.ServletException;  
    03.import javax.servlet.http.HttpServlet;  
    04.import javax.servlet.http.HttpServletRequest;  
    05.import javax.servlet.http.HttpServletResponse;  
    06.public class Hello extends HttpServlet {  
    07.    /** 
    08.     * Constructor of the object. 
    09.     */  
    10.    public Hello() {  
    11.       super();  
    12.       System.out.println("new Hello");  
    13.    }  
    14.    /** 
    15.     * Destruction of the servlet. <br> 
    16.     */  
    17.    public void destroy() {  
    18.       super.destroy(); // Just puts "destroy" string in log  
    19.       // Put your code here  
    20.       System.out.println("destroy");  
    21.    }  
    22.    /** 
    23.     * The doGet method of the servlet. <br> 
    24.     * This method is called when a form has its tag value method equals to get. 
    25.     * @param request the request send by the client to the server 
    26.     * @param response the response send by the server to the client 
    27.     * @throws ServletException if an error occurred 
    28.     * @throws IOException if an error occurred 
    29.     */  
    30.    public void doGet(HttpServletRequest request, HttpServletResponse response)  
    31.           throws ServletException, IOException {         
    32.       String text1 = request.getParameter("text1");  
    33.            String str = text1;  
    34.            response.sendRedirect("result.jsp?text1=" + text1);     
    35.}  
    36.    /** 
    37.     * The doPost method of the servlet. <br> 
    38.     * This method is called when a form has its tag value method equals to post. 
    39.     * @param request the request send by the client to the server 
    40.     * @param response the response send by the server to the client 
    41.     * @throws ServletException if an error occurred 
    42.     * @throws IOException if an error occurred 
    43.     */  
    44.    public void doPost(HttpServletRequest request, HttpServletResponse response)  
    45.           throws ServletException, IOException {  
    46.           doGet(request,response);  
    47.    }  
    48.    /** 
    49.     * Initialization of the servlet. <br> 
    50.     * @throws ServletException if an error occure 
    51.     */  
    52.    public void init() throws ServletException {  
    53.       // Put your code here  
    54.        System.out.println("init");  
    55.    }  
    56.}