hello friends i have an error int entrance of the login page that is
look i have an
jsp and
servlet
i have two admin
one admin name : dinesh password :dinesh
another admin :ramesh password :ramesh
the output is success if the admin name is ramesh and error if the admin name is dinesh could somebody explain me
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html ><head>
<title>UrbanArtist</title>
<link rel="stylesheet" href="seconddata_files/UrbanArtist.css" type="text/css">
</head><body>
<form action="http://localhost:8084/finalhealth/admindatabase" method="POST">
<br><br><br><br><font face="Century Schoolbook"><font size="5">ADMIN LOG ON SCREEN<br><br></font></font>
<CENTER>
<table width="348" border="1" align="center" height="208">
<tbody><tr>
<td> USERNAME</td>
<td> <input type="text" size="15" name="username"></td></tr>
<tr>
<td> PASSWORD</td>
<td> <input type="text" size="15" name="password"></td></tr>
<tr>
<td align="center" valign="middle"> <input type="submit" value="SUBMIT"></td>
<td align="center"> <input type="reset" value="CANCEL"></td></tr>
</tbody></table><br><div align="center">
</div>
</CENTER>
</form>
</body></html>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.net.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author a
*/
public class admindatabase extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = null ,password = null;
String user = request.getParameter("username");
String pass = request.getParameter("password");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/javatest", "root", "conrad");
Statement stmt = con.createStatement();
String sql = "select * from admin";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
username = rs.getString("admin_id");
password = rs.getString("admin_password");
}
out.println(username);
out.println(password);
rs.close();
stmt.close();
} catch (SQLException ex) {
out.println(ex);
} catch (ClassNotFoundException ex) {
out.println(ex);
}
if(username.equals(user)&& password.equals(pass))
{
out.println("passed");
}
else
{
out.println("failed");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}