Link to home
Start Free TrialLog in
Avatar of clonmelog
clonmelog

asked on

URGENT: unknown error with login page

Hi,

Im attempting to create a login in jsp with the following form and jsp page to process it....

home.jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<br>
<br>
<head>
<title>Momentum Marketing Intranet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../ROOT/Momentum/text.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: 14px}
.style2 {
      font-family: "Times New Roman", Times, serif;
      font-size: 16px;
}
-->
</style>
</head>

<body bgcolor="#FFFFFF">
<table width="770" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td bgcolor="#FFFFFF"><table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><a href="../ROOT/Momentum/index.jsp"><img src="../ROOT/Momentum/mom_logo.gif" width="256" height="74" border="0"></a></td>
          <td width="411">&nbsp;</td>
        </tr>
        <tr>
          <td width="359"><img src="../ROOT/Momentum/leftbar.gif" width="359" height="39"></td>
          <td align="right" bgcolor="336CA1">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2"><img src="../ROOT/Momentum/topbar.gif" width="770" height="69"></td>
        </tr>
        <tr>
          <td colspan="2">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" background="../ROOT/Momentum/but_bg.gif">
              <tr>
                <td align="right"><img src="../ROOT/Momentum/spacer.gif" width="15" height="23"><img src="../ROOT/Momentum/spacer.gif" width="15" height="23"><img src="../ROOT/Momentum/spacer.gif" width="15" height="23"><img src="../ROOT/Momentum/spacer.gif" width="15" height="23"><img src="../ROOT/Momentum/spacer.gif" width="15" height="23"><img src="../ROOT/Momentum/spacer.gif" width="45" height="23"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="167" rowspan="3" valign="top" bgcolor="8FBEE8">&nbsp;          </td>
          <td colspan="2" align="center"><table width="95%" border="0" cellpadding="5" cellspacing="0" class="text">
              <tr>
                <td class="text"><font color="#000000"><span class="style1"><br>
                      <span class="style2">Welcome to the Momentum Marketing company Intranet. Please authenticate yourself with our database to access the administration section. </span></span><br>
                  <br>
                </font></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td width="588" align="center"> <form name="form1" method="post" action="adminresult.jsp">
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="17%"><strong>Username:</strong></td>
                    <td width="83%"><input name="Username" type="text" id="Username"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="17%"><strong>Password:</strong></td>
                    <td width="83%"><input name="Password" type="password" id="Password"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <p>
              <input type="submit" name="Submit" value="Submit">
            </p>
            <p><br>
              </p>
          </form>
            </td>
          <td width="15" align="center" valign="top">&nbsp; </td>
        </tr>
        <tr>
          <td colspan="2" valign="bottom"><table width="82%" border="0" cellspacing="0" cellpadding="8">
              <tr>
                <td align="center" valign="bottom"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">&copy;
                  2005 Momentum Marketing Services Ltd.</font></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>


adminresult.jsp:

<%@ page import="java.sql.*" %>

<html>
<head>
<title>Admin Verification</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "witnt07.wit.ie";
        String portNumber = "1521";
        String sid = "orawit";

        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "W01445693";
        String password = "EPEDXZ";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver");
    } catch (SQLException e) {
      e.printStackTrace();
        out.println( "Could not connect to the database");
    }
      
%>

<%

session.setAttribute("Username",request.getParameter("Username"));

try
{
    String user = request.getParameter("Username");
    String formPassword = request.getParameter("Password");
      String Password = null;

 
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("select Pass from Supervisor WHERE Username = '" + user + "'");


      if( formPassword == null) {
            String redirectURL = "/momentum/error.jsp";
        response.sendRedirect(redirectURL);
      }
      else {
            if( rs.next() )
            {
                  Password = rs.getString("Password");
                                          
                  if( formPassword.equals( Password ) )
                  {
                        //login sucess
                        
            String redirectURL = "/momentum/adminoptions.jsp";
        response.sendRedirect(redirectURL);


                  
                  }
                  else
                  {
                        //login failed
                        
            String redirectURL = "/momentum/error.jsp";
        response.sendRedirect(redirectURL);
      
                  }
                  
            }
            else
            {
                  //Login failed
            String redirectURL = "/momentum/error1.jsp";
        response.sendRedirect(redirectURL);
            }
      }
 }
 
finally
{
    connection.close();
}

%>
 
</body>
</html>


the error that im getting is as follows:

type Exception report

message Internal Server Error

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

exception

java.lang.NullPointerException
      at org.apache.jsp.adminresult$jsp._jspService(adminresult$jsp.java:144)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
      at java.lang.Thread.run(Thread.java:536)


Sorry about the length of my post. Im not all that familiar with JSP so im not even sure where the error might be coming from!

any ideas??

thanks!
Avatar of fargo
fargo

Hi,

Please go to the work directory of tomcat.

tomcat-path/work/org/apache/jsp/adminresults/adminresult$jsp.java

and check the line 144.

There is some variable which is getting null.
Let us know if you have problem understanding the line 144 in the java file.

regards,
fargo
Hi,

Moreover, Password = rs.getString("Password");
 is not correct.

this should be Password = rs.getString("Pass");

OR use SELECT Pass AS Password FROM....

in the query to make the present jsp work.

fargo
Avatar of clonmelog

ASKER

  connection.close();

is at line 144..... would this be a problem?
Avatar of bloodredsun
This would indicate that the connection object is null and that you never create a connection

Also, you have a try statement with no catch only a finally

try
{
    String user = request.getParameter

("Username");
...//where is the catch block after this?

This maybe why it is not working
Hi,

did you check in the work directory???

Moreover, if connection.close() is at line 144. It means, at first step u are not able to get the connection.
Please put some logging information in-between to check whether u are able to get the connection or not??

fargo
good catch...bloodredsun.

fargo
sorry, ive just checked my original code and im missing this at the end:

 }
               
            // end
            // HTML // begin [file="/adminresult.jsp";from=(94,2);to=(98,0)]
                out.write("\r\n \r\n</body>\r\n</html>\r\n");

            // end

        } catch (Throwable t) {
            if (out != null && out.getBufferSize() != 0)
                out.clearBuffer();
            if (pageContext != null) pageContext.handlePageException(t);
        } finally {
            if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
        }
    }
}

I forgot to put that in the original post, aplogies!
well, the code you posted just now is from the generated java file.

fargo
very droll fargo :-)
sorry about that,

OK code now is:

<%@ page import="java.sql.*" %>

<html>
<head>
<title>Admin Verification</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "witnt07.wit.ie";
        String portNumber = "1521";
        String sid = "orawit";

        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "W01445693";
        String password = "EPDEXZ";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver");
    } catch (SQLException e) {
 e.printStackTrace();
        out.println( "Could not connect to the database");
    }
 
%>

<%

session.setAttribute("Username",request.getParameter("Username"));

try
{
    String user = request.getParameter("Username");
    String formPassword = request.getParameter("Password");
 String Password = null;

 
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("select Pass from Supervisor WHERE Username = '" + user + "'");


 if( formPassword == null) {
  String redirectURL = "/momentum/error.jsp";
        response.sendRedirect(redirectURL);
 }
 else {
  if( rs.next() )
  {
   Password = rs.getString("Pass");
       
   if( formPassword.equals( Password ) )
   {
    //login sucess
   
  String redirectURL = "/momentum/adminoptions.jsp";
        response.sendRedirect(redirectURL);


   
   }
   else
   {
    //login failed
   
  String redirectURL = "/momentum/error.jsp";
        response.sendRedirect(redirectURL);
 
   }
   
  }
  else
  {
   //Login failed
  String redirectURL = "/momentum/error1.jsp";
        response.sendRedirect(redirectURL);
  }
 }
 }
 
finally
{
    connection.close();
}

%>
 
</body>
</html>


works other than the fact that its redirecting to error.jsp despite the fact that the correct details are being entered and the tables in the db are correct.
catch block is again missing.

fargo
ah i see....

How would i go about coding that catch in?
} catch(Exception ex){
System.out.println("Exception", ex);
}finally
{
    connection.close();
}

fargo
getting this error now:

An error occurred between lines: 37 and 97 in the jsp file: /adminresult.jsp

Generated servlet error:
D:\tomcat4\work\Standalone\localhost\_\adminresult$jsp.java:139: 'catch' without 'try'.
                 } catch(Exception ex){
The last section should be this

            try
            {
                String user = request.getParameter("Username");
                String formPassword = request.getParameter("Password");
             String Password = null;

                                      Statement stmt = connection.createStatement();
                                       ResultSet rs = stmt.executeQuery("select Pass from Supervisor WHERE Username = '" + user + "'");



             if( formPassword == null) {
              String redirectURL = "/momentum/error.jsp";
                    response.sendRedirect(redirectURL);
             }
             else {
              if( rs.next() )
              {
               Password = rs.getString("Pass");
                   
               if( formPassword.equals( Password ) )
               {
                //login sucess
               
              String redirectURL = "/momentum/adminoptions.jsp";
                    response.sendRedirect(redirectURL);


               
               }
               else
               {
                //login failed
               
              String redirectURL = "/momentum/error.jsp";
                    response.sendRedirect(redirectURL);
             
               }
               
              }
              else
              {
               //Login failed
              String redirectURL = "/momentum/error1.jsp";
                    response.sendRedirect(redirectURL);
              }
             }
             }catch(Exception ex){
                   System.out.println("Exception", ex);
             }finally
            {
                connection.close();
            }

fargo
still getting this error:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occurred between lines: 37 and 96 in the jsp file: /adminresult.jsp

Generated servlet error:
D:\tomcat4\work\Standalone\localhost\_\adminresult$jsp.java:141: Wrong number of arguments in method.
                                System.out.println("Exception", ex);

Sorry. The exception should be like

System.out.println(ex.getMessage());

fargo


You seem to have this in hand fargo so I'll unsub now :-)
bloodredsun, if you are around...my points are always in danger... -:)
Anyway, this should be your question. You catch the catch.

fargo
ha! These are your points, you worked for them and I have more than enough :-)

In fact I'm looking forward to see who will become the next featured expert (highest scorer of the last month - on the left hand nav) between you, radarsh and TimYates as it won't be me anymore.
hi bloodredsun. Thanks for encouraging words. BTW, radarsh and Tim are oldies...and they are the real experts. I am just started to hang around more. You cannot be touched.....

fargo
Won't be me ;-)  I can't get a look in here or in Java these days ;-)

My poor old hands just aren't quick enough ;-)

heheheh
old hands! Watch it mate I'm older than you so what does that say about me! ;-)
hehehe soz granddad ;-)

*runs off to bed and pretends to be asleep* ;-D

See y'all tomorrow :-)
Are you using JRE 1.5 ??? and more on which servlet engine are you using (tomact) or web server are you using???

and 1st please try this & then get back.

change the catch block as follows.

catch(Exception ex){
             ex.printStackTrace();
           }
fargo,

im still getting the same error im afraid. the page isnt logging in despite the fact that the code is correct

shivaspk, ive tried yours and i get the following error:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.

D:\tomcat4\work\Standalone\localhost\_\adminresult$jsp.java:155: Type expected.
        } catch (Throwable t) {
          ^
1 error, 1 warning
Can you check the value for the following in the adminresult.jsp page

String user = request.getParameter("Username");
String formPassword = request.getParameter("Password");
String Password = rs.getString("Pass");

post the values for the above three values.

regards,
fargo
try
                {
                    String user = request.getParameter("Username");
                    String formPassword = request.getParameter("Password");
                      String Password = null;
               
                 
                    Statement stmt = connection.createStatement();
                    ResultSet rs = stmt.executeQuery("select Pass from Supervisor WHERE Username = '" + user + "'");
               
               
                      if( formPassword == null) {
                            String redirectURL "/momentum/error.jsp";
                      response.sendRedirect(redirectURL);
                      }
               else {
                if( rs.next() )
                      {
                      Password = rs.getString("Password");
                                                          
              if( formPassword.equals( Password ) )
                                  {
                            //login sucess
                                        
                            String redirectURL = "/momentum/adminoptions.jsp";
                        response.sendRedirect(redirectURL);
               
what is it that you posted??

fargo
sorry ive misunderstood what you asked there, i thought you meant to post the values carrying into the java file.

what exactly do you mean?
I mean the following

String user = request.getParameter("Username");
System.out.println("User is "+user);

String formPassword = request.getParameter("Password");
System.out.println("formPassword is "+formPassword);

String Password = rs.getString("Pass");
System.out.println("Password is "+Password);

We can then expect the results.
fargo
where abouts do i place this code beacuse ive tried it like this below and no luck:

String user = request.getParameter("Username");
                    System.out.println("User is "+user);

              String formPassword = request.getParameter("Password");
                    System.out.println("formPassword is "+formPassword);
           String Password = null;

                                      Statement stmt = connection.createStatement();
                                       ResultSet rs = stmt.executeQuery("select Pass from Supervisor WHERE Username = '" + user + "'");



           if( formPassword == null) {
            String redirectURL = "error.jsp";
                  response.sendRedirect(redirectURL);
           }
           else {
            if( rs.next() )
            {
             Password = rs.getString("Pass");
                   System.out.println("Password is "+Password);

all it does is spit back the error1.jsp page to me.
Hi,

If it is going to error1.jsp..it means the formPassword is null. You can check the output in console for the above we did.
are you using logging like log4j etc.?

fargo
no im not using any logging... im very new to java as you can see ;-)

Perhaps my form is the problem?

<form name="form1" method="post" action="adminresult.jsp">
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="17%"><strong>Username:</strong></td>
                    <td width="83%"><input name="Username" type="text" id="Username"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="17%"><strong>Password:</strong></td>
                    <td width="83%"><input name="Password" type="password" id="Password"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <p>
              <input type="submit" name="Submit" value="Submit">
            </p>
            <p><br>
              </p>
          </form>
Hi,

form seems to be fine.

>> You can check the output in console for the above we did
have u checked this???

You definitely has to check what values you are getting from the form and against what you are checking.

fargo
How do you mean in console?
I have it, one moment.
www.templateit.net/doc1.doc

thats the result coming from the console!
good. What is coming with the resultset then?

rs.getString("Pass");

fargo
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial