<!-- Author : Jagbir Singh -->
<!-- Debug : Amanbir Singh -->
<!-- Tested : Siddhesh Surve -->

 <%
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0); 
    %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page language="java" import="java.sql.*,javax.sql.DataSource, javax.naming.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
DataSource pool;

Connection conn = null;

PreparedStatement pstmt = null;
String feedBack = request.getParameter("feedback");
String user = request.getParameter("userId");
String id = (String)session.getAttribute("sUserName");
String query = null;
System.out.println(feedBack);
System.out.println(user);
System.out.println(id);



  try{
	  InitialContext ctx = new InitialContext();
      
       pool = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
      if (pool == null)
         throw new SQLException("Unknown DataSource 'jdbc/TestDB'");


   // Get a connection from the pool
      conn = pool.getConnection();
      // Open a connection

     query = ("INSERT into sendComment " +
             "(userId, docId, comment) "+
             "values ('"+user+"', '"+id+"', '"+feedBack+"')");
  
     pstmt = conn.prepareStatement(query);    
      pstmt.executeUpdate(query);
      
      pstmt.close();
      conn.close();
      
  }catch(SQLException se){
      //Handle errors for JDBC
      se.printStackTrace();
   }catch(Exception e){
      //Handle errors for Class.forName
      e.printStackTrace();
   }finally{
      //finally block used to close resources
      try{
         if(pstmt!=null)
            pstmt.close();
      }catch(SQLException se2){
      }// nothing we can do
      try{
         if(conn!=null)
         conn.close();
      }catch(SQLException se){
         se.printStackTrace();
      }//end finally try
   } //end try


%>




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert FeedBack</title>
</head>
<body>

<form name="home" " action="welcome.jsp">
<input type="image" src="home.jpg" alt="Submit" align="left" width="70" height="60">
</form>
<form name="graph" " action="logout.jsp">
<input type="image" src="logout.jpg" alt="Submit" align="right" width="60" height="60">
</form>

<h3>YOur FeedBack has been successfully inserted</h3>
</body>
</html>