Question

how to solve

Asked by: Ananthakrishnan_K

Hi All,
 Yesterday I sent a question. I got the solution but I tried to implement all still am not getting solved. Still am getting the error in the condition "if (idHandler.authenticate(userName, passWord))" in validateuser.jsp file.

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /validateuser.jsp at line 18

15: <%
16: String userName = request.getParameter("userName");
17: String passWord = request.getParameter("passWord");
18: if (idHandler.authenticate(userName, passWord)){
19: System.out.println("login is successfull");
20: } else {
21: response.sendRedirect("retry.jsp");


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
      com.mycompany.login.Login.authenticate(Login.java:42)
      org.apache.jsp.validateuser_jsp._jspService(validateuser_jsp.java:83)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Please get me a solution. I attached the code below.
 Thank you.

<-------- index.jsp--------------->
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="validateuser.jsp" method="POST">
username - <input type="text" name="userName">
password - <input type="password" name="passWord">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
                  <----------validateuser.jsp---------------->
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collections" %>
<jsp:useBean id="idHandler" class="com.mycompany.login.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<body>
<%
String userName = request.getParameter("userName");
String passWord = request.getParameter("passWord");
if (idHandler.authenticate(userName, passWord)){
System.out.println("login is successfull");
} else {
response.sendRedirect("retry.jsp");
}
%>
</body>
</html>
 
     <------------------- login.java----------------------->
 
package com.mycompany.login;
 
import java.sql.*;
import java.io.*;
 
public class Login {
	
 
	//default constructor
	public Login(){}
 
	//method for the catabase connection
	public Connection getConnection()
	throws IOException{
	Connection conn = null;
	try{
	Class.forName("com.mysql.jdbc.Driver");
	conn = DriverManager.getConnection(
	"jdbc:mysql:@localhost:3036:anantha",
	"root",
	"buser");
	}
	catch(SQLException e)
	{
	System.out.println("SQLException: " + e.getMessage());
	while((e = e.getNextException()) != null)
	System.out.println(e.getMessage());
	}
	catch(ClassNotFoundException e)
	{
	System.out.println("ClassNotFoundException: " + e.getMessage());
	}
	return conn;
	}
 
	//method that is called from validateuser.jsp and this checks for the authentic user and
	public boolean authenticate(String user, String pass)
	throws SQLException, IOException{
	String Username = null; 
	String Password = null;
	Login dbconn = new Login();
	Statement stmt = dbconn.getConnection().createStatement();
	String sql = "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='" + user + "'" + "AND PASSWORD='" + pass + "'";
	ResultSet rs = stmt.executeQuery(sql);
	if(rs.next()){
	Username = rs.getString("USER_NAME");
	Password = rs.getString("PASSWORD");
	}
	if(Username != null && Password != null && user.equals(Username) && pass.equals(Password)){
	//return true;
		return (Username != null && Password != null && Username.equals(user) && Password.equals(pass));
		}
	else return false;
	}
	}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-01 at 00:35:37ID24776138
Tags

eclipse

,

java

,

jsp

,

mysql

Topics

MySQL Server

,

Eclipse

,

WebApplications

Participating Experts
2
Points
500
Comments
47

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. The server encountered an internal error () that prevente…
    Hi, I tried running the progrm that worked yesterday today and i got the error.I don't know why, could you pls help. Description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException org....
  2. Exception stackTrace to a file
    Hello how do I print the complete stackTrace of an exception to a File rather than the consoleMenu. Since the e.printStackTrace() is a void ..is there a way to get it to a file. I want to capture the stackTrace to file rather than to a console Menu
  3. Stacktrace in C++
    How can i get the Stacktrace (Backtrace) in a C++ Application same as in Java. I would like to add this feature to my Exceptions. Linux as well as Windows! Thanks in Advance
  4. Hide StackTrace in Exception
    Hi, I am trapping errors and throwing it. But it shows all the details of the Stack Trace with it. How do I hide this ? I do not want to display the StackTrace details to the users. Thanks for all your help.
  5. Fulfill conditions in vb
    i have 2 table. i want add new record in table 1 but first it must fulfilled the condition in table 2. how should i code it? Secondly, it seem cant update the record in table 2. attach are my coding. thanks

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Bart_CrPosted on 2009-10-01 at 00:41:17ID: 25466607

Remove the if test in the login:

if(Username != null && Password != null && user.equals(Username) && pass.equals(Password)){
   //return true;
   return (Username != null && Password != null && Username.equals(user) && Password.equals(pass));
} else return false;
 
 
// becomes
return (Username != null && Password != null && Username.equals(user) && Password.equals(pass));
                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: kadabaPosted on 2009-10-01 at 14:42:07ID: 25473471

see jsp:useBean

have print statements to debug

 

by: Ananthakrishnan_KPosted on 2009-10-06 at 00:31:59ID: 25502538

i tried with the solutions given. But still I  am not getting the solution for the above problem

 

by: kadabaPosted on 2009-10-06 at 00:42:53ID: 25502603


<jsp:useBean id="idHandler" class="com.mycompany.login.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

This will access your bean, for a better understanding of the tag
refer : http://www.jsptut.com/Forms.jsp

idHandler.authenticate(userName, passWord)

here idHandler is actually not defined.. you have to import your class and then validate.

go through the useBean and get back to me

 

by: Ananthakrishnan_KPosted on 2009-10-06 at 04:18:16ID: 25503735

Hi kadaba

 can you help me out...

 

by: kadabaPosted on 2009-10-07 at 20:06:04ID: 25522111

change your validateuser.jsp, and make authenticate method as static as
public static boolean authenticate(...

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collections" %>
<%@page import="com.mycompany.login.Login" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<body>
<%
String userName = request.getParameter("userName");
String passWord = request.getParameter("passWord");
if (Login.authenticate(userName, passWord))
{
	out.println("login is successfull");
} 
else 
{
	response.sendRedirect("retry.jsp");
}
%>
</body>
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

Select allOpen in new window

 

by: Ananthakrishnan_KPosted on 2009-10-07 at 22:01:56ID: 25522416

Hi kadaba

 I did the changes as you told. But once i fill the username and the password and click the submit button am getting this error. Am getting this error on UI screen only. The error as follows:

HTTP Status 404 - /project2/validateuser.jsp

--------------------------------------------------------------------------------

type Status report

message /project2/validateuser.jsp

description The requested resource (/project2/validateuser.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

 

by: Ananthakrishnan_KPosted on 2009-10-07 at 22:10:51ID: 25522437

Am getting a problem with the condition in validateuser.jsp.
The condition is
  if (login.authenticate(userName, passWord))

 Also I have attached the code.


                     <index.jsp>
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="validateuser.jsp" method="POST">
username - <input type="text" name="userName">
password - <input type="password" name="passWord">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
 
 
                         <validateuser.jsp>
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.util.*" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collections" %>
<%@page import="com.mycompany.login.login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String userName = request.getParameter("userName");
String passWord = request.getParameter("passWord");
if (login.authenticate(userName, passWord))
{
	out.println("login is successfull");
} 
else 
{
	response.sendRedirect("retry.jsp");
}
%>
</body>
</html>
 
 
                    <login.java>
 
package com.mycompany.login;
 
import java.sql.*;
import java.io.*;
 
 
public class login {
	//default constructor
	public login(){}
 
	//method for the catabase connection
	public Connection getConnection()
	throws IOException{
	Connection conn = null;
	try{
	Class.forName("com.mysql.jdbc.Driver");
	conn = DriverManager.getConnection(
	"jdbc:mysql:@localhost:3036:anantha",
	"root",
	"buser");
	}
	catch(SQLException e)
	{
	System.out.println("SQLException: " + e.getMessage());
	while((e = e.getNextException()) != null)
	System.out.println(e.getMessage());
	}
	catch(ClassNotFoundException e)
	{
	System.out.println("ClassNotFoundException: " + e.getMessage());
	}
	return conn;
	}
 
	//method that is called from validateuser.jsp and this checks for the authentic user and
	public boolean authenticate(String user, String pass)
	throws SQLException, IOException{
	String userName = null; 
	String passWord = null;
	login dbconn = new login();
	Statement stmt = dbconn.getConnection().createStatement();
	String sql = "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='" + user + "'" + "AND PASSWORD='" + pass + "'";
	ResultSet rs = stmt.executeQuery(sql);
	if(rs.next()){
	userName = rs.getString("USER_NAME");
	passWord = rs.getString("PASSWORD");
	}
	if(userName != null && passWord != null && user.equals(userName) && pass.equals(passWord)){
	//return true;
		return (userName != null && passWord != null && userName.equals(user) && passWord.equals(pass));
		}
	else return false;
	}
	}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:

Select allOpen in new window

 

by: kadabaPosted on 2009-10-07 at 22:14:42ID: 25522448

1) make sure all your pages are in one folder say pages and try
else make sure you set the path right . right click on validate user.jsp and run it on the server see the path, in index page you need to give the same path(relative path)

2)  public boolean authenticate(String user, String pass) should be made static
as
public static boolean authenticate(String user, String pass)

 

by: Ananthakrishnan_KPosted on 2009-10-07 at 22:45:33ID: 25522545

All the pages are in same folder  and i changed  "public boolean authenticate(String user, String pass)  to "public static boolean authenticate(String user, String pass)" .But when I tried to run validateuser.jsp,its giving the error like

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /validateuse.jsp at line 17

14: <%
15: String userName = request.getParameter("userName");
16: String passWord = request.getParameter("passWord");
17: if (login.authenticate(userName, passWord))
18: {
19:       out.println("login is successfull");
20: }


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
      com.mycompany.login.login.authenticate(login.java:41)
      org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

 

by: Ananthakrishnan_KPosted on 2009-10-07 at 23:03:46ID: 25522605

Hi kadaba

All the pages are in same folder  and i changed  "public boolean authenticate(String user, String pass)  to "public static boolean authenticate(String user, String pass)" .But when I tried to run validateuser.jsp,its giving the error like

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /validateuse.jsp at line 17

14: <%
15: String userName = request.getParameter("userName");
16: String passWord = request.getParameter("passWord");
17: if (login.authenticate(userName, passWord))
18: {
19:       out.println("login is successfull");
20: }


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
      com.mycompany.login.login.authenticate(login.java:41)
      org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

 

by: kadabaPosted on 2009-10-07 at 23:08:47ID: 25522621

Statement stmt = dbconn.getConnection().createStatement();

instead of this lets split and debug

Connection connection =  dbconn.getConnection();

if(connection == null)
{
   System.out.println("The connection object is null");
}

Statement stmt = connection.createStatement();

 

by: kadabaPosted on 2009-10-07 at 23:13:31ID: 25522646

also check in your console if you are getting any sql exception

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 00:58:32ID: 25522993

Hi  kadaba
 
 I changed the getConnection part as your previous reply but when i tried to run validateuser.jsp am getting the error like

Oct 8, 2009 1:06:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:project2' did not find a matching property.
Oct 8, 2009 1:06:44 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;C:\PROGRA~1\Borland\CBUILD~1\Bin;C:\PVSW\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
Oct 8, 2009 1:06:44 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Oct 8, 2009 1:06:44 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 363 ms
Oct 8, 2009 1:06:44 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 8, 2009 1:06:44 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
Oct 8, 2009 1:06:44 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 8, 2009 1:06:44 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 8, 2009 1:06:44 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/16  config=null
Oct 8, 2009 1:06:44 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 282 ms
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null
Oct 8, 2009 1:18:10 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at com.mycompany.login.login.authenticate(login.java:50)
      at org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null
Oct 8, 2009 1:22:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at com.mycompany.login.login.authenticate(login.java:50)
      at org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)

Am fininding difficult to understand the error  "ClassNotFoundException: com.mysql.jdbc.Driver" in the above console. What  exactly the error could be?

And when i tried to run "index.jsp" am getting the error like

HTTP Status 404 - /project2/validateuser.jsp

--------------------------------------------------------------------------------

type Status report

message /project2/validateuser.jsp

description The requested resource (/project2/validateuser.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

Please help me with the things.

 

by: kadabaPosted on 2009-10-08 at 02:22:43ID: 25523383

ok not a problem.

ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null


This means you have not put the mysql connector jar. you can google this and get the jar. After that make sure you have it in your class path and the build path.

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 02:43:59ID: 25523471

Hi  kadaba

Should I need to copy it physically or through eclipse

 

by: kadabaPosted on 2009-10-08 at 03:04:55ID: 25523569

1> right click on your project
2> click on proeprties
3> click on Java Build Path
4> Choose the third tab Libraries
5> Add External JARs
6> Select the JAR
7> click ok

and also copy it in your projects lib folder which is under WEB-INF/lib

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 03:31:38ID: 25523731

Hi  kadaba
 
     I did as you said.Now am not getting "class not found"  exception.
 
     But now i tried to run the index.jsp.Their after giving username and password and clicking the submit button, am getting the error like

HTTP Status 404 - /project2/validateuser.jsp

--------------------------------------------------------------------------------

type Status report

message /project2/validateuser.jsp

description The requested resource (/project2/validateuser.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20



   And also i tried to compile validateuser.jsp but am getting the error like

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
      com.mycompany.login.login.authenticate(login.java:50)
      org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

 

by: kadabaPosted on 2009-10-08 at 03:39:25ID: 25523779

see in your console if you got any exception.... I guess its now not connecting to the database.. .

See according to the logic in getConnection, if you happen to get any exception you will log the error and still return the connection object which will be null.

So you should either get class not found or SQL exception. We first got class not found due to this line
Class.forName("com.mysql.jdbc.Driver"); It could not find the class. So now we resolved that problem.

check in your console for SQL exception and the reason. If no exception occurs you will get a valid connection object.

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 04:16:15ID: 25524024

Hi  kadaba

Yes it is showing null pointer exception.It is showing in the UI screen only. Its all happening after compiling validateuser.jsp.
The errror which is in UI screen is as follows
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
      com.mycompany.login.login.authenticate(login.java:50)
      org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20


The one which is showing in the system console is as follows

Oct 8, 2009 4:03:20 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:project2' did not find a matching property.
Oct 8, 2009 4:03:20 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;C:\PROGRA~1\Borland\CBUILD~1\Bin;C:\PVSW\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
Oct 8, 2009 4:03:20 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Oct 8, 2009 4:03:20 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 366 ms
Oct 8, 2009 4:03:20 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 8, 2009 4:03:20 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
Oct 8, 2009 4:03:20 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 8, 2009 4:03:20 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 8, 2009 4:03:20 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15  config=null
Oct 8, 2009 4:03:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 264 ms
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null
Oct 8, 2009 4:27:07 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at com.mycompany.login.login.authenticate(login.java:50)
      at org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)
Oct 8, 2009 4:35:10 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at com.mycompany.login.login.authenticate(login.java:50)
      at org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null
Oct 8, 2009 4:43:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at com.mycompany.login.login.authenticate(login.java:50)
      at org.apache.jsp.validateuse_jsp._jspService(validateuse_jsp.java:72)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)



 

by: kadabaPosted on 2009-10-08 at 06:17:44ID: 25524994

No the error still says
ClassNotFoundException: com.mysql.jdbc.Driver
The connection object is null

that means its not referring to the class.

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 23:07:41ID: 25532656

Hi  kadaba

     Frankly speaking am new to this language.Can you please help with the code. What is to be done if it is not referring to the class.

 

by: Ananthakrishnan_KPosted on 2009-10-08 at 23:34:18ID: 25532729

Hi  kadaba

    I attached the modified code. Please help me.


                        <index.jsp>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="validateuser.jsp" method="POST">
username - <input type="text" name="userName">
password - <input type="password" name="passWord">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
 
             
                   <validateuser.jsp>
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.util.*" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collections" %>
<%@page import="com.mycompany.login.login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String username = request.getParameter("userName");
String password = request.getParameter("passWord");
if (login.authenticate(username, password))
{
	out.println("login is successfull");
} 
else 
{
	response.sendRedirect("retry.jsp");
}
%>
</body>
</html>
 
                          <login.java>
 
package com.mycompany.login;
 
import java.sql.*;
import java.io.*;
 
 
public class login {
	//default constructor
	public login(){}
 
	//method for the catabase connection
	public Connection getConnection()
	throws IOException{
	Connection conn = null;
	try{
	Class.forName("com.mysql.jdbc.Driver");
	conn = DriverManager.getConnection(
	"jdbc:mysql:@localhost:3036:anantha",
	"root",
	"buser");
	}
	catch(SQLException e)
	{
	System.out.println("SQLException: " + e.getMessage());
	while((e = e.getNextException()) != null)
	System.out.println(e.getMessage());
	}
	catch(ClassNotFoundException e)
	{
	System.out.println("ClassNotFoundException: " + e.getMessage());
	}
	return conn;
	}
 
	//method that is called from validateuser.jsp and this checks for the authentic user and
	public static boolean authenticate(String user, String pass)
	throws SQLException, IOException{
	String username = null; 
	String password = null;
		
	login dbconn = new login();
	//PreparedStatement stmt = (PreparedStatement) dbconn.getConnection().createStatement();
 
	Connection connection =  dbconn.getConnection();
 
	if(connection == null)
	{
	   System.out.println("The connection object is null");
	}
 
	Statement stmt = connection.createStatement();
 
	String sql = "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='" + user + "'" + "AND PASSWORD='" + pass + "'";
	ResultSet rs = stmt.executeQuery(sql);
	if(rs.next()){
	username = rs.getString("USER_NAME");
	password = rs.getString("PASSWORD");
	}
	if(username != null && password != null && user.equals(username) && pass.equals(password)){
	//return true;
		return (username != null && password != null && username.equals(user) && password.equals(pass));
		}
	else return false;
	}
	}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:

Select allOpen in new window

 

by: Bart_CrPosted on 2009-10-08 at 23:44:46ID: 25532765

Try this:

                        <index.jsp>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="validateuser.jsp" method="POST">
username - <input type="text" name="userName">
password - <input type="password" name="passWord">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
 
             
                   <validateuser.jsp>
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.util.*" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collections" %>
<%@page import="com.mycompany.login.login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String username = request.getParameter("userName");
String password = request.getParameter("passWord");
if (login.authenticate(username, password)) {
    out.println("login is successfull");
} else {
    response.sendRedirect("retry.jsp");
}
%>
</body>
</html>
 
                          <login.java>
 
package com.mycompany.login;
 
import java.sql.*;
import java.io.*;
 
 
public class Login {
    //default constructor
    private Login(){}
 
    //method for the catabase connection
    public static Connection getConnection() throws IOException {
        Connection conn = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql:@localhost:3036:anantha", "root", "buser");
	} catch(SQLException e) {
            System.out.println("SQLException: " + e.getMessage());
            while((e = e.getNextException()) != null) System.out.println(e.getMessage());
	} catch(ClassNotFoundException e) {
            System.out.println("ClassNotFoundException: " + e.getMessage());
	}
	return conn;
    }
 
    //method that is called from validateuser.jsp and this checks for the authentic user and
    public static boolean authenticate(String user, String pass) throws SQLException, IOException{
        String username = null; 
	String password = null;
		
	Connection connection =  getConnection();
 
	if (connection == null) {
	   System.out.println("The connection object is null");
	}
 
	Statement stmt = connection.createStatement();
 
	String sql = "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='" + user + "'" + "AND PASSWORD='" + pass + "'";
	ResultSet rs = stmt.executeQuery(sql);
	if(rs.next()){
            username = rs.getString("USER_NAME");
            password = rs.getString("PASSWORD");
        }
	return (username != null && password != null && username.equals(user) && password.equals(pass));
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:

Select allOpen in new window

 

by: Ananthakrishnan_KPosted on 2009-10-09 at 00:09:57ID: 25532850

Hi Bart Cr

I changed the code accroding to the one which  u sent but after clicking the submit button in UI screen am getting the error like

HTTP Status 404 - /project2/validateuser.jsp

--------------------------------------------------------------------------------

type Status report

message /project2/validateuser.jsp

description The requested resource (/project2/validateuser.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

 

by: Ananthakrishnan_KPosted on 2009-10-11 at 21:56:59ID: 25548692

Hi Bart Cr

    Can you help me with the problem? Please..!!

 

by: kadabaPosted on 2009-10-11 at 22:34:25ID: 25548764

Hi Anantha,

I will try to put up a sample, give me sometime...
refer post Id 25523569, In which I explained you to include the jar in two places. This would solve the class not found error.

I will try to post soon

 

by: Ananthakrishnan_KPosted on 2009-10-13 at 04:39:27ID: 25558873

Hi  kadaba
 U told like you will post the things. Am waiting for it. Or else can you give me the sample code for the login form using java,jsp,servlets and mysql using eclipse tool. Am in need of it. So please can you make it fast. I need solve this problem as soon as possible. So please help me out.

 

by: kadabaPosted on 2009-10-13 at 07:05:56ID: 25560058

in ten min I will code and post it ...

 

by: kadabaPosted on 2009-10-13 at 07:39:36ID: 25560410

I have attached the files.
I had over looked a few things.

read the readme.txt for getting the complete picture

let me know

 

by: kadabaPosted on 2009-10-13 at 07:41:54ID: 25560443

PS: remove.txt extension from all files

 

by: kadabaPosted on 2009-10-15 at 00:55:38ID: 25578233

You got this working?

 

by: Ananthakrishnan_KPosted on 2009-10-15 at 22:36:11ID: 25587220

Hi kadaba
 
     Thanks for your patience and help. I did everything as it is in zip file which u sent. Now its compiling properly without any error. But the thing is eventhough i give correct username and password its printing     "hmmm try again "  which is else part of validateuser.jsp.So its not authenticating the username and password. And i got one more doubt. In my database part I gave
 
   Table name as userlogin which I created
   Database name as anantha
   Username as root
   Password as buser
So should I need to change it in   "  conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/UserData", "root", "password");   ....?

 

by: kadabaPosted on 2009-10-15 at 22:54:19ID: 25587268

Yes ... you need to change only this.

conn = DriverManager.getConnection(
           "jdbc:mysql://localhost:3306/anantha", "root", "buser");


I tested this with the same table name so it should work..[If you happen to change the table name and columns change the query
String sql =
        "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='"
       + user + "'" + "AND PASSWORD='" + pass + "'";

]
In the same file you have a main method in the end, you can use it for testing.

Give the user name and password in this file where I have given authenticate("ananth","ananth");  to test.

You right click on the file and run as java application you should be able to test it manually. If this works , run the application on server and it should give the same result.

I will stick around let me know

 

by: Ananthakrishnan_KPosted on 2009-10-15 at 23:14:49ID: 25587333

Hi kadaba

     I changed the things but it still giving the same output. I also tried in the main class but it is giving the error which is irrelevant to my code it is giving the error
HTTP Status 404 - /forms1/f2.jsp

--------------------------------------------------------------------------------

type Status report

message /forms1/f2.jsp

description The requested resource (/forms1/f2.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20

But I worked with this f2.jsp yesterday.I dont  know why it is showing here. Even I restarted the server and i tried but still am getting the same error. And one more important thing is I haven't created any table within eclipse.I created  the tables in a tool called sqlyog. But I have given the same database name,username and password in dbconnection which i have given in sqlyog.

 

by: kadabaPosted on 2009-10-15 at 23:26:05ID: 25587359

that's weird..

I assume you changed only the Login.java
You need to do this..

right click on the java file, you will have an option to run as java application[DO NOT CHOOSE RUN ON SERVER]

I have given ananth and ananth as the parameters to authenticate, give the user name and password you want to validate.

In your console , see the messages that comes.

package com.test.ananth.login;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class Login
{
    /**
     * Default constructor: can do some initialization 
     * activities.
     */
    public Login()
    {
		
    }
 
    /**
     * Method to get the connection object
     * 
     * @return a valid connection object provided the 
     * driver to connect to the MySQL is valid and the database 
     * which is being connected to exists. 
     * 
     * In all other cases null will be returned.
     * 
     * This is made private since we do not need
     * it anywhere else. This  can be pushed to a helper class or a 
     * Utility class if required.
     */
    private static Connection getConnection()
    {
	Connection conn = null;
	try
	{
	    // Register the driver to connect to the database.	
	    // get the new instance
	    Class.forName("com.mysql.jdbc.Driver").newInstance();
	    /*
	     *  The first parameter is the URL which is used to connect to 
	     *  the database.
	     *  
	     *  The second parameter is the user name.
	     *  
	     *  The third parameter is the password.
	     *   
	     */
	    conn = DriverManager.getConnection(
		    "jdbc:mysql://localhost:3306/anantha", "root", "buser");
	}
	catch (SQLException e)
	{
	    System.out.println("SQLException: " + e.getMessage());
	    while ((e = e.getNextException()) != null)
		System.out.println(e.getMessage());
	} 
	catch (ClassNotFoundException e)
	{
	    System.out.println("ClassNotFoundException: " + e.getMessage());
	}
	catch(IllegalAccessException e)
	{
	    System.out.println("Class Access Error: " + e.getMessage());
	}
	catch(InstantiationException e)
	{
	    System.out.println("Class Access Error: " + e.getMessage());
	}
	// Al the above exceptions can be caught using the parent exception 
	// Exception
	return conn;
    }
 
    /**
     * Method to validate the user
     * 
     * @param user the user name to be validated.
     * 
     * @param pass the password of the user to be validated along with the user
     *  name
     *  
     * @return true if the user is authentic.
     * 
     * @throws SQLException in case of errors during the DB operations
     */
    public static boolean authenticate(String user, String pass) 
    throws SQLException
    {
	String Username = null;
	String Password = null;
	
	// Holds the connection object
	Connection con;
	// Holds the statement
	Statement stmt;
	// holds the data set of the database operation
	ResultSet rs;
	
	// get the connection object
	con = getConnection();
	
	if(con == null)
	{
	    System.out.println("Invalid connection object! cannot proceed!");
	    return false;
	}
	else
	{
	    stmt = getConnection().createStatement();
	}
	
	// SQL to get validate the user
	String sql = 
	    "SELECT USER_NAME,PASSWORD FROM userlogin WHERE USER_NAME='"
	    + user + "'" + "AND PASSWORD='" + pass + "'";
	
	rs = stmt.executeQuery(sql);
	
	if (rs.next())
	{
	    Username = rs.getString("USER_NAME");
	    Password = rs.getString("PASSWORD");
	}
	if (Username != null && Password != null && 
	     user.equalsIgnoreCase(Username)&& pass.equalsIgnoreCase(Password))
	{
	    return true;
	    
	} 
	else
	{
	    return false;
	}
    }
    
    /**
     * This is a test method to see if everything is working fine.
     * We can then call this from a JSP.
     * 
     * @param args
     */
    public static void main(String args[])
    {
	try
	{
	    boolean isValidUser = authenticate("ananth","ananth");
	    
	    if(isValidUser)
	    {
		System.out.println("Yes Validated!");
	    }
	    else
	    {
		System.out.println("Intruder!");
	    }
	}
	catch(SQLException exception)
	{
	    System.out.println("No fault from my side, All your fault!");	
	}
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:

Select allOpen in new window

 

by: kadabaPosted on 2009-10-15 at 23:28:48ID: 25587366

also try this as a separate web project so that once things fall in place you can merge with others if you have.. I am assuming when you ran it picked up the reference to that page.

 

by: Ananthakrishnan_KPosted on 2009-10-15 at 23:43:05ID: 25587400

Hi kadaba

     Its giving the correct output "yes validated" when run Login.java on java application.But it is giving the error when I tried ro run it on server.
  I maintained in a separate web project.But it is in same workspace

 

by: kadabaPosted on 2009-10-15 at 23:57:19ID: 25587436

so some good news :)
that's ok you can have it in the same work space.

Right click on the web project and run it on the server - while doing so, you will be prompted which all projects will be deployed, you remove all other projects and choose only this project ok and then try this should definitely solve it

if it says resource not found(I am assuming you are using the code I provided which contains the index.jsp as the start up page, so you do not need to do the below , but if its not the case ...)
then in the browser give it as
http://localhost:8080/TestProject/jspname.jsp

let me know

 

by: Ananthakrishnan_KPosted on 2009-10-16 at 00:55:12ID: 25587620

Hi kadaba

Am doing from the beginning with this method only. I always use to choose the project which I want to run and its not saying like " resource not found".  It is taking it.

 

by: kadabaPosted on 2009-10-16 at 02:25:29ID: 25587930

when you run on server,
if you dont have an index page it will give you
http://localhost:8080/TestProject/
and this will be undefined. Are you running the code I gave?

Whats the URL in the browser?


 

by: Ananthakrishnan_KPosted on 2009-10-16 at 03:34:37ID: 25588202

Hi kadaba

      Yes am running the code which you gave to me.
       When I run on the server am getting this url
      http://localhost:8080/TestProject1/index.jsp

After pressing the submit button am getting this url
http://localhost:8080/TestProject1/validateuser.jsp

But Eventhough I give correct username and password, am getting the output  "hmmm try again ".

 

by: Ananthakrishnan_KPosted on 2009-10-16 at 03:37:56ID: 25588220

Hi kadaba

Am using this sql connector "mysql-connector-java-5.0.8-bin".

 

by: kadabaPosted on 2009-10-16 at 03:46:41ID: 25588252

I assume you checked with java and it worked fine right... from the page make sure the names are going with out spaces

 

by: Ananthakrishnan_KPosted on 2009-10-19 at 08:28:26ID: 25606067

Hi  kadaba

            Everything going fine.

 

by: kadabaPosted on 2009-10-19 at 08:38:27ID: 25606195

Hi...

Is everything working?

 

by: Ananthakrishnan_KPosted on 2009-10-20 at 22:14:00ID: 31635759

Thanks for your patience and for solution.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...