sos.print("{success:true}");
sos.close();
- What is sos?
- Whay do we close sos?
- Where does it print, in the console or somewhere.
Is it something like a return statement
return "{success:true}";
Can i also pass my ajax response like this
Update... I have updated the entire code here.
protected void process(HttpServletRequest request, HttpServletResponse response) {
try {
ServletOutputStream sos = response.getOutputStream();
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setContentType("text/plain");
String name = request.getParameter("name");
String age = request.getParameter("age");
String city = request.getParameter("city");
String phone = request.getParameter("phone");
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("City: " + city);
System.out.println("Phone: " + phone);
String query ="INSERT INTO CRUD_DATA VALUES('"+name+"',"+age+",'"+city+"',"+phone+")";
System.out.println("Query:" + query);
OracleDataSource ods = new OracleDataSource();
ods.setUser("abdel");
ods.setPassword("password");
ods.setURL("jdbc:oracle:thin:@//127.0.0.1/XE");
Connection conn = ods.getConnection();
Statement statement = conn.createStatement();
statement.executeUpdate(query);
conn.commit();
conn.close();
sos.print("{success:true}");
sos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}