aspose file tools*
The moose likes Servlets and the fly likes error to login page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "error to login page" Watch "error to login page" New topic
Author

error to login page

dineshiop kumar
Greenhorn

Joined: Mar 05, 2009
Posts: 13
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>
}
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

dineshiop please UseCodeTags while posting source codes. It makes the code readable. I've added some comments to your code to help you with your problem







SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
dineshiop kumar
Greenhorn

Joined: Mar 05, 2009
Posts: 13
what is the condition please say me
Surya Kant
Ranch Hand

Joined: Mar 29, 2005
Posts: 104
Hi Dinesh,
Your logic to find the existence of user is wrong.You are iterating through all the records of admin table
& assigning it to same variable.Thats why only "ramesh" is getting logged in it to your system.User Where clause for
finding the user.Hope you understood.
dineshiop kumar
Greenhorn

Joined: Mar 05, 2009
Posts: 13
mean to say i should write the clause like this

select user , password from admin where user = a and password = b
even though i use i how to compare the data and display can anybody say
dineshiop kumar
Greenhorn

Joined: Mar 05, 2009
Posts: 13
ANYBODY THERE TO HELP ME
Surya Kant
Ranch Hand

Joined: Mar 29, 2005
Posts: 104
Yes you are correct.Execute the query with user name & password which you have got from request.If Resultset returns some entries then it means login successful.Otherwise fail.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Geesh, I was about to post a very helpful and detailed answer until I read this:

dineshiop kumar wrote:ANYBODY THERE TO HELP ME


Impatiently kicking a topic up after less than 10 minutes and shouting to the world, while the other half of the world is still asleep at the time you posted it, is really not the way to get respect from others.

Please read this: http://faq.javaranch.com/java/PatienceIsAVirtue (and all other links in it).
uttam chandu
Greenhorn

Joined: Mar 24, 2009
Posts: 4
hello "kumar"....
just wait i will try for u....
try to see tomorrow
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61241
    
  66

dineshiop kumar wrote:ANYBODY THERE TO HELP ME


As Bauke pointed out, this is extremely rude and is not constructive to getting your question answered. Do not do this again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
uttam chandu
Greenhorn

Joined: Mar 24, 2009
Posts: 4
Hi Kumar,

I have gone through your code.... change the query as
"String sql = "select * from admin where admin_id=user and admin_password=pass";
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just wondering, did you really need 2 days to find this out? At any way, this isn't the core problem. There is much more at matter.
uttam chandu
Greenhorn

Joined: Mar 24, 2009
Posts: 4
hello mister..... i had gone through that code and compiled that code also.... i got result also..... don't loose words ok........ hold your controllllll....
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That you got result doesn't explicitly mean that the code is written proper and efficient and working in all circumstances. And please work on your attitude.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error to login page