This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes what's wrong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "what Watch "what New topic

what's wrong

Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
The following is java bean
import java.sql.*;
public class UserInfoBean {
private String username;
private String password;
private boolean validUsername;
private boolean validPassword;
private String driver="sun.jdbc.odbc.JdbcOdbcDriver";
private String protocol="jdbc dbc:db";

public UserInfoBean() {
try {
} catch(ClassNotFoundException e) {}
public void setUsername(String username) {
this.username = username;
public void setPassword(String email) {
this.password = password;
public String getUsername() {
return username;
public String getPassword() {
return password;
public boolean isValidUsername() {
return validUsername;
public boolean isValidPassword() {
return validPassword;
public void registerSupportRequest() throws SQLException
Connection connection = null;
connection = DriverManager.getConnection(protocol);
//verify Username
PreparedStatement pstmt1 =connection.prepareStatement(selectUsername);
ResultSet rs1 = pstmt1.executeQuery();
if (
validUsername= true;
String user=getUsername();
String password=getPassword();
String selectPassword ="SELECT PASSWORD FROM MEMBER WHERE USERNAME='"+(user)+"' and password='"+(password)+"'";
//verify password
Statement stmt = connection.createStatement();
ResultSet rst2=stmt.executeQuery(selectPassword);

else {
validUsername= false;
finally {
if (connection != null) {
try {
} catch (SQLException sqle) {}
Now this the process.jsp file that i call whenever the user logins.
<%@ page language="java"%>
<%@ page errorPage="error.jsp"%>
<jsp:useBean id="userInfo" scope="session" class="UserInfoBean"/>
<jsp:setProperty name="userInfo" property="*"/>
<% userInfo.registerSupportRequest() ; %>
<% if (userInfo.isValidUsername())
if (userInfo.isValidPassword())
{ %>
<jsp:forward page="valid.jsp"/>
<% }
else {%>
<jsp:forward page="invalid1.jsp"/>
else { %>
<jsp:forward page="invalid.jsp"/>
<% } %>
In the above code why do i always get an invalid password even though i enter the correct password.
Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
I'm a newbie to servlets and the like but I did notice your line of code here
public void setPassword(String email) {
this.password = password;
My guess is that it should probably be:
public void setPassword(String email) {
this.password = email;
//OR maybe this:
public void setPassword(String password) {
this.password = password;
Hope that helps
[This message has been edited by Amber Woods (edited May 25, 2001).]

"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
Hey Amber,
That certainly is a mistake not supposed to be repeated.Thanks for the pointer.
I agree. Here's the link:
subject: what's wrong
It's not a secret anymore!