The Artima Developer Community
Sponsored Link

Java Answers Forum
problem creating login system

3 replies on 1 page. Most recent reply: Jun 16, 2004 11:03 PM by Uma

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
chong

Posts: 2
Nickname: hoong2003
Registered: Jun, 2004

problem creating login system Posted: Jun 15, 2004 2:44 AM
Reply to this message Reply
Advertisement
im creating a web site with a login system using jsp.This is the bean that i've created to verufy the username and password.The exception part is not working when i run the jsp on the browser using tomcat server.Please help me up with this program.

package studentloginbeans;
import java.sql.*;

public class StudentVerifier
{
private String bnDbDriver="org.gjt.mm.mysql.Driver";
private String bnDbId="jdbc:mysql://127.0.0.1:3306/coursediarydb";
private String bnDbUser="root";
private String bnDbPassword="";
private String bnId="no-id";
private String bnPassword="no-password";

public void setBnId(String argId)
{ bnId=argId.trim(); }

public String getBnId()
{ return bnId; }

public void setBnPassword(String argPassword)
{ bnPassword=argPassword.trim(); }

public String getBnPassword()
{ return bnPassword; }

public String StudentLogin()
{
try
{
Class.forName(bnDbDriver);
Connection myConnection=DriverManager.getConnection(bnDbId,bnDbUser,bnDbPassword);

Statement myStatement=myConnection.createStatement();
String sqlQuery="SELECT dbName from student where dbId='"+bnId+"' and dbPassword='"+bnPassword+"'";
myStatement.executeQuery(sqlQuery);
}
catch(Exception e)
{
System.out.println("StudentVerifier.StudentLogin():"+e);
return "<jsp:forward page='"+"relogin.jsp'>"
+"<jsp:param name='"+"forwardedFrom'"+" value='"+"inbox.jsp'/>"
+"</jsp:forward>";
}
return dbName;
}
}


Uma

Posts: 4
Nickname: chumma
Registered: Jun, 2004

Re: problem creating login system Posted: Jun 15, 2004 10:32 AM
Reply to this message Reply
Hi,

Can you paste the error message in the tomcat/log ?
You are invoking a non static method SudentLogin() on the class StudentVerifier.Is this compiling first?

Uma

chong

Posts: 2
Nickname: hoong2003
Registered: Jun, 2004

Re: problem creating login system Posted: Jun 16, 2004 2:28 AM
Reply to this message Reply
This is another login system that i've created using servlet.but when i compile it,there's 14 error message appear.please help me up.

package studentshowservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class LoginServlet extends HttpServlet
{
private String bnDbDriver="org.gjt.mm.mysql.Driver";
private String bnDbId="jdbc:mysql://127.0.0.1:3306/coursediarydb";
private String bnDbUser="root";
private String bnDbPassword="";

public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
doGet(request,response);
}

public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
Class.forName(bnDbDriver);
Connection myConnection=DriverManager.getConnection(bnDbId,bnDbUser,bnDbPassword);
response.setContentType("text/html");

String studentId=request.getParameter("frmId");
String studentPassword=request.getParameter("frmPassword");
Statement myStatement=myConnection.createStatement();
String sqlQuery1="Select dbId from student where dbId='"+studentId+"'";
String sqlQuery2="Select dbPassword from student where dbPassword='"+studentPassword+"'";
ResultSet myResultSet1=myStatement.executeQuery(sqlQuery1);
ResultSet myResultSet2=myStatement.executeQuery(sqlQuery2);
String result1=myResultSet1.getString("dbId");
String result2=myResultSet2.getString("dbPassword");
System.out.println("LoginServlet.doGet():studentId="+studentId);
System.out.println("LoginServlet.doGet():studentPassword="+studentPassword);
if((studentId==result1)&&(studentPassword==result2))
{
forwardTo("inbox.jsp",request,response);
}
else
{
forwardTo("relogin.jsp",request,response);
}
}

private void forwardTo(String url,HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
RequestDispatcher myReqDisp;
myReqDisp=getServletContext().getRequestDispatcher(url);
myReqDisp.forward(request,response);
}
}

Uma

Posts: 4
Nickname: chumma
Registered: Jun, 2004

Re: problem creating login system Posted: Jun 16, 2004 11:03 PM
Reply to this message Reply
Hi,

You have not included the servlet.jar (the jar which contains the servlet classes) in the class path of the java environment you are working with.

Uma

Flat View: This topic has 3 replies on 1 page
Topic: Integrating JSP and Flash Previous Topic   Next Topic Topic: Hel...help...help...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use