I use jsp to send data to the servlet, but after posting the data I want to stay back in jsp. Briefly: 1) I have jsp here with 2 text fields. I use javascript to copy data from one to another when a button is clicked. 2) I use the same button to send data to the database. 3) I want both actions to be performed at the same time, and should not go to the third jsp (the result of the servlet message), but I need to switch to another jsp that I use.
I can handle these 2 things separately, but together I cannot do this. the data is updated in the database and shows a new line in the first text (that I am mistaken, I use the redirection method) or moves data from the first text field to another and does not post the data. please help me with this. below is the piece of code that I used to do this.
java script to copy data and published data:
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";
}
methods for the button are declared as follows:
<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>
and the servlet code that I used is 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 publish the data in the same way as the value of the text field copied to the second text field, since I will use it for my further reference.
thank
source
share