I have following program can any one help me to find out wat is te error in it, it is login successfully, but on login failed it is not redirect to the loginfom.jsp page,
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String uid, psw; // creating local variables for storing data which are taken from Form Fields.
uid = request.getParameter("uid"); // getting data from Form Field using Fileld name.
psw = request.getParameter("psw");
Class.forName("com.mysql.jdbc.Driver"); // creating database connection
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "root", "nbuser"); //loading jdbc Drivers
String q = "select * from user where user='" + uid + "' AND password='" + psw + "'"; // writing SQL Query
java.sql.Statement st = con.createStatement();
ResultSet rs = st.executeQuery(q); // executing SQL Query
String dpsw, duid; // creating local variables for storing data which are taken from Form databse.
while (rs.next()) {
duid = rs.getString(1);
dpsw = rs.getString(2);
can you try opening and closing the PrintWriter from within your if block since, you don't need to work with response till the login is successful. See if your luck favors!!