提交jsp表单后仍保留在同一页面

我正在使用jsp将数据发布到servlet,但在发布数据后我想留下来查看jsp。
简要:
1)我在这里有一个带有2个文本框的jsp。我使用javascript按钮点击将数据从一个复制到另一个。
2)我使用相同的按钮将数据发布到数据库。
3)我希望这两个动作一次完成,不应该转到第三个jsp(servlet post结果),但是,应该转到我使用的另一个jsp。

I'm using a jsp to post data to a servlet, but after posting the data i want to stay back insame jsp. Briefly: 1) I have a jsp here with 2 textboxes. i use a javascript to copy data from one to another on a button click. 2) I use the same button to post data to a database. 3) I want both the actions to be done at a time and should not go to the third jsp(servlet post result), but , should go to another jsp i use.

我能够单独处理这两件事,但我无法做到这一点。数据在数据库中更新并在第一个文本中显示一个新行(这是我的错误,我正在使用重定向方式)或将数据从第一个文本框移动到另一个文本框并且不进行数据发布。请帮我解决这个问题。下面是我用来做的代码。

i'm able to handle these 2 things seperately but together i'm unable to do it. the data gets updated in database and shows a new line in the first text(that's my fault i'm using the redirect way) or moves the data from first textbox to another and doesn't do the data posting. please help me about doing it. below is the code piece i used to do it.

用于复制数据和发布数据的java脚本是:

java script to copy data and post data are:

function move(){  

document.getElementById('tgt1').value = document.getElementById('Allocation').value;  
document.getElementById('Allocation').value="";  
document.getElementById("Send").disabled=true;  

}
function invoke(but)  
  {  
   if(but==0)   
    {  
        document.myform.action="Alloc_Insert.do";  
    }  

按钮的方法声明如下:

<table><tr><center><td><input type="Submit" value="Allocate" id="Send"     onClick="invoke(0);move();" style="width:150px" style="font-size:100%"/></td></center></tr>    </table> 

我使用的servlet代码如下。

and the servlet code i used are as follows.

ResultSet rs=null;  
        String Add=request.getParameter("tgt1");  
        String user=(String) session.getAttribute("myusername");  
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();Date d1 = new Date();    
        String d1_str = new SimpleDateFormat("yyyy-MM-dd").format(d1);   
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");  
        PreparedStatement ps=con.prepareStatement("UPDATE SCOPE1 SET ALLOCATED='"+d1_str+"', SPECIALIST='"+user+"' WHERE DBID='"+Add+"'");  
        con.setAutoCommit(true);  
        int i=ps.executeUpdate();  
        if(i==1)  
                           {  
             String redirectURL= "Update_Counts.jsp";  
            response.sendRedirect(redirectURL);  
                        }  
                   else{  

            out.print("retry");  
                  }  

我想发布数据以及与文本框值相同的数据复制到第二个文本框,因为我将它用于我的进一步参考。

i want to post the data aswell as be on the same with the textbox value copied into second textbox, as i would be using it for my further referrence.

谢谢



 1 条回答