Dear All,
I have created a servlet that does authentication here is the following code
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.util.Enumeration; import javax.faces.context.FacesContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import oracle.jdbc.pool.OracleDataSource; public class Authentication extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter pw=response.getWriter(); pw.write("<b>Authenticating please wait.....</b>"); pw.flush(); pw.close(); Enumeration enu = request.getParameterNames(); String userID = request.getParameter("userid"); String password = request.getParameter("password"); String port = request.getParameter("port"); String database = request.getParameter("database"); String server = request.getParameter("server"); OracleDataSource ds; try { Class.forName("oracle.jdbc.OracleDriver"); Connection con =DriverManager.getConnection("jdbc:oracle:oci8:@"+database, userID, password); System.out.println("Authentication Sucess := "+con.isValid(1)); response.sendRedirect(request.getContextPath() + "/faces/template.jsp"); } catch (Exception e) { System.out.println("Authentication failed"); response.sendRedirect(request.getContextPath() + "/faces/authfailed.jsp"); } } }
I can make servlet to implement SingleThreadModel but it is not recommended.So how can i make my code to be thread safe..should i make doGet method to be synchronized ???
-Thanks