• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

error to login page

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
}
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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





 
dineshiop kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the condition please say me
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ANYBODY THERE TO HELP ME
 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello "kumar"....
just wait i will try for u....
try to see tomorrow
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
uttam chandu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Oh the stink of it! Smell my tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic