You can invoke ajax in your jsp like this:
function test(tg1){
context = '${pageContext.request.contextPath}';
var http_request = getXMLHttpRequest();
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.open("POST", context + "/ServletName?tgt1=" + tg1, true);
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var response = http_request.responseText;
//do something if you have a response from the servlet
}
}
};
http_request.send(null);
}
In your servlet, remove your redirect code.
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();
You can add a response from the servlet using response.getWriter().write("something");