Hi there experts!!
I am trying to write a login bean for my site. I currently have:
package webtech;
import java.util.Properties;
public class loginbean
{
private Properties userinfo = new Properties();
public loginbean() {
userinfo.put("danielbryant", "mullet1234");
userinfo.put("mattcorcoran", "mullet1234");
}
public boolean checkUser(String inUserID, String inPassword) {
if (inUserID == null)
return false;
if (inPassword == null)
return false;
if (userinfo.getProperty(inUserID) != null && userinfo.getProperty(inUserID).equals(inPassword))
return true;
return false;
}
}
as my bean and my jsp looks like this:
<%@ page contentType="text/html;charset=windows-1252"%>
<jsp:useBean id="mybean" scope="session" class="webtech.loginbean" />
<%
if (request.getParameter("Submit") != null) {
if (mybean.checkUser(request.getParameter("Username"), request.getParameter("Password"))) {
RequestDispatcher rd = getServletConfig().getServletContext().getRequestDispatcher("/main.jsp");
rd.forward(request, response);
}
}
%>
I am using the following form actions on my page:
<form name="login" action="/index.jsp" method="post"></p>
Username:<br />
<input type="text" name="Username"><p />
Password:<br />
<input type="password" name="Password"><p />
<input type="submit" Value="Login" Name="Submit" onclick="validateForm(); if (send=='no') {return false}">
</form>
What i want this to do is check the values entered on the form against the usernames and passwords lited in the bean. If they are the same then they should be redirected to main.jsp. If they are different they should stay in index.jsp. This currently does not do this and due to my lack of experience with these i'm not too sure why. Can anyone help me with this at all? Any help would be greatly appreciated.
Many thanks
public boolean checkUser(String inUserID, String inPassword) {
if (inUserID == null)
return false;
if (inPassword == null)
return false;
if (userinfo.getProperty(inUs
return true;
}
else {
return false;
}
}
I would test with a print statment to see if this part works : something like this..
if (mybean.checkUser(request.
out.println("User validated");
}
if that works then I would check to see what's wrong with the jsp forward.
hope that helps,
Ghost