[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

User Login bean SQL

hey Kennethxu and rrz
 hey guys
again it is Gaz

i have used the code from before for a couple of forms successfully
i am working on a login page for the application
i can get the data from the user and validate it but i want to be able to check the entered
email,username and password  against those in the database table

here is what i have so far but i am a bit lost, can you help out?:

  public void userlogCheck() throws ClassNotFoundException, SQLException  {
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;
PreparedStatement ps = null;
                  
try {
conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany");
  ps = conn.prepareStatement( "SELECT EmailAddress, Username, Password FROM UserRegInformation    WHERE EmailAddress = ?" +      "AND Username = ? AND Password = ?)" );
              
  ps.getString( 1, emailAddress);
  ps.getString( 2, userName );
  ps.getString( 3, repassWord );
  }
finally {
         if( ps != null )
          try {ps.close(); }
        catch( Throwable t ) { t.printStackTrace(); }
         if( conn!=null)
         try {conn.close(); }
  catch( Throwable t ) { t.printStackTrace(); }
                                  
   }
            
    }      
0
Gar04
Asked:
Gar04
  • 23
  • 18
  • 2
  • +1
2 Solutions
 
objectsCommented:
looks like you are on the right track, you need to now execute the query and see if you got any results:

...
ps = conn.prepareStatement( "SELECT EmailAddress, Username, Password FROM UserRegInformation    WHERE EmailAddress = ?" +     "AND Username = ? AND Password = ?)" );
           
  ps.getString( 1, emailAddress);
  ps.getString( 2, userName );
  ps.getString( 3, repassWord );
ResultSet rs = ps.executeQuery();
if (rs.next())
{
   // found the user do as required
}
else
{
   // nothing return, invalid login
}
...
0
 
Gar04Author Commented:
is it possible to make this a boolean method
because i think that it would make more sense to me and i think that i could
do the redirection in jsp or is this completely wrong???
gaz

public boolean userlogCheck() throws ClassNotFoundException, SQLException  {
       
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn = null;
      PreparedStatement ps = null;

                  
            try {
                  if (!isValid() ){
                 throw new SQLException( "invalid data - from UserRegBean.insertData" );
                 }
                 else {
                  
                  conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany");
                    ps = conn.prepareStatement( "SELECT EmailAddress, Username, Password FROM UserRegInformation UserRegInformation WHERE"
                    + "EmailAddress = ? AND Username = ? AND Password = ?)" );
              
                    ps.setString( 1, emailAddress);
                    ps.setString( 2, userName );
                    ps.setString( 3, passWord );
                    ResultSet rs = ps.executeQuery();
                  
                        if (rs.next()) {
                              
                        return true;      here, i would like to redirect the user to another jsp page
                     
                        }
                              else {
                                 return false; here i would like to return the user to the login page and call the     propertyStat
                              }

                          }
              
                    }
                  
                  finally {
                                  if( ps != null )
                                
                                  try {ps.close(); }
                                
                                  catch( Throwable t ) { t.printStackTrace(); }
                                  
                                
                                  if( conn!=null)
                                
                                  try {conn.close(); }
                                
                                  catch( Throwable t ) { t.printStackTrace(); }
                                  
                               
                               }
            
    }      
0
 
Gar04Author Commented:
i think that i have confused myself with the isValid method and how i would go about using these emthod in the jsp page
essentially if the data is valid(i.e. the correct type of data and is entered) i want it then to check if the data matches the data in the database, moreover, if the data matches i would like to redirect to the appropriate page if not return to the login page with the appropriate message from propertyStatusMsg.

should i make userlogCheck() a boolean, is this possible??

the isValid() method looks like so:
public boolean isValid() {
       return firstName != null &&
                  lastName != null && orgName != null && 
            StringFormat.isValidEmailAddr(emailAddress) && userName != null &&
            passWord != null && repassWord != null && repassWord.equals(passWord);
       }

if this is not valid it goes to the propertyStatusMsg() method:

public String getPropertyStatusMsg() {
               
               String msg ="Thank you for registering!";
          if (!isInitialized ()) {
          msg ="Please enter values in all fields";
          }
          else if (!isValid()) {
          msg ="The Following data is missing or invalid: ";
          }
          return msg;
          
          }
          
    public String[] getPropertyStatusDetails() {
    Vector details = new Vector();
    if (isInitialized() && !isValid()) {
          
   
          if (emailAddress == null) {
                      details.addElement("An Email Address is Missing");
                      }
                else if (!StringFormat.isValidEmailAddr(emailAddress))  {
                                  details.addElement("Invalid Email Format:"+emailAddress+",try this format:'bob@name.com'");
                            }
                            
                            
          if (userName == null) {
                      details.addElement("A User Name is Missing");
                      }      
                      
          if (passWord == null) {
                      details.addElement("A Password is Missing");
                      }
                      
   
          }
          
          String[] arr = new String[details.size()];
          details.copyInto(arr);
          return arr;
    }      
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Gar04Author Commented:
this compiles fine but i need to test it to see if it works

is it correct to make this a boolean??
0
 
Gar04Author Commented:
hey there seems to be a problem with this

 ps.getString( 1, emailAddress);
  ps.getString( 2, userName );
  ps.getString( 3, repassWord );
ResultSet rs = ps.executeQuery();
 the compiler doesn't like the getString() it cannot resolve symbol??
sos about before i had setString() by mistake and it compiled but i don't think that would work in ru time??

gaz
0
 
kennethxuCommented:
you need to use ps.setString, not getString. that's the problem
0
 
kennethxuCommented:
for sure you can make it boolean and you did it very well ;-)
0
 
Gar04Author Commented:
cheers
i'll test it and should i require your(pl) assistance i know where to find yee
slan
Gaz
0
 
Gar04Author Commented:
hey guys

 <% if(Bean2.isValid())
 Bean.isUser();%>

how can i get this to forward to the appropriate page if isUser() is true
 can i nestle a <jsp:forward: page "main.jsp"/> into it like this :
<% if(Bean2.isValid())
 Bean.isUser <jsp:forward: page "main.jsp"/>;%>
or shall i i just call it seperately
like:
<% if(Bean2.isUser())
<jsp:forward: page "main.jsp"/>;%>
????
i can't find a good example
0
 
Gar04Author Commented:
another general question but relative


if a user registers and his data is correct is there a way to send them to a conformation page
that loads for like 10 second
and says "thanks for registering" and displays their registration details and then forwards the user to the main page

i guess it would be like a pop up page or someting
and would that mean that i have to have session scope for all???
0
 
kennethxuCommented:
<% if( Bean2.isValid() && Bean2.isUser() ) { %>
  <jsp:forward: page "main.jsp"/>
<% } %>
0
 
kennethxuCommented:
Yes, the confirmation page should have:
<% response.setHeader( "Refresh", "10; main.jsp" ); %>
0
 
Gar04Author Commented:
hey thats great!
however, i am having a bit of bother with the same thing on another page:
 obviously i can't do this??

<% if(Bean1.isValid())
Bean1.insertData(); %>

<% if( Bean1.isValid() && Bean1.insertData() ) { %>
 <jsp:forward: page "Success.jsp"/>
<% } %>
 how do i get it to forward even though it has already called the methods
and the buffer has been flushed
i hope that i understood that right and that you do too??
gaz
0
 
kennethxuCommented:
you need to put the code in the beginning of your jsp page. can you show me the page?
0
 
Gar04Author Commented:
i will show you the login.jsp as it is a little smaller but has the same problem
i thought the code would have to go into the form because that is where the two functions are being process
i guess i won't get good marks for layout, it is all over the shop!!!
sorry

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<jsp:useBean id="Bean2" class="com.ora.jsp.beans.userinfo.UserLoginBean" scope="request"/>
<jsp:setProperty name="Bean2" property="*"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>User Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript"function mmLoadMenus() {
  if (window.mm_menu_1_0) return;
      window.mm_menu_1_0 = new Menu("root",181,16,"Times New Roman, Times, serif",10,"#000000","#FFFFFF","#000084","center","middle",1,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_1_0.addMenuItem("48 Sheet Billboard Format"Shopperlite"Commuterlites");
   mm_menu_1_0.hideOnMouseOut=true;
   mm_menu_1_0.bgColor='#336666';
   mm_menu_1_0.menuBorder=1;
   mm_menu_1_0.menuLiteBgColor='#336666'
   mm_menu_1_0.menuBorderBgColor='#000000'
  window.mm_menu_0309135707_0 = new
  mm_menu_0309135707_0.addMenuItem("48&nbsp;Sheet&nbsp;Billboard&nbsp;Format"Shopperlites");
   mm_menu_0309135707_0.hideOnMouseOut=true;
   mm_menu_0309135707_0.bgColor='#336666'
   mm_menu_0309135707_0.menuBorder=1;
   mm_menu_0309135707_0.menuLiteBgColor='#336666'
   mm_menu_0309135707_0.menuBorderBgColor='#000000'

  window.mm_menu_0309140128_0 = new
  mm_menu_0309140128_0.addMenuItem("Belfast&nbsp;City&nbsp;Area"Northern&nbsp;Ireland");
   mm_menu_0309140128_0.hideOnMouseOut=true;
   mm_menu_0309140128_0.bgColor='#336666'
   mm_menu_0309140128_0.menuBorder=1;
   mm_menu_0309140128_0.menuLiteBgColor='#336666'
   mm_menu_0309140128_0.menuBorderBgColor='#000000'

  window.mm_menu_0309133610_0 = new
  mm_menu_0309133610_0.addMenuItem(");
   mm_menu_0309133610_0.hideOnMouseOut=true;
   mm_menu_0309133610_0.bgColor='#336666'
   mm_menu_0309133610_0.menuBorder=1;
   mm_menu_0309133610_0.menuLiteBgColor='#336666'
   mm_menu_0309133610_0.menuBorderBgColor='#000000'

  window.mm_menu_0316175720_0 = new
  mm_menu_0316175720_0.addMenuItem(");
   mm_menu_0316175720_0.hideOnMouseOut=true;
   mm_menu_0316175720_0.bgColor='#336666'
   mm_menu_0316175720_0.menuBorder=1;
   mm_menu_0316175720_0.menuLiteBgColor='#336666'
   mm_menu_0316175720_0.menuBorderBgColor='#000000'

mm_menu_0316175720_0.writeMenus();
} // mmLoadMenus()ogin></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript"function mmLoadMenus() {
  if (window.mm_menu_1_0) return;
      window.mm_menu_1_0 = new Menu("root",181,16,"Times New Roman, Times, serif",10,"#000000","#FFFFFF","#000084","center","middle",1,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_1_0.addMenuItem("48 Sheet Billboard Format"Shopperlite"Commuterlites");
   mm_menu_1_0.hideOnMouseOut=true;
   mm_menu_1_0.bgColor='#336666';
   mm_menu_1_0.menuBorder=1;
   mm_menu_1_0.menuLiteBgColor='#336666'
   mm_menu_1_0.menuBorderBgColor='#000000'
  window.mm_menu_0309135707_0 = new
  mm_menu_0309135707_0.addMenuItem("48&nbsp;Sheet&nbsp;Billboard&nbsp;Format"Shopperlites");
   mm_menu_0309135707_0.hideOnMouseOut=true;
   mm_menu_0309135707_0.bgColor='#336666'
   mm_menu_0309135707_0.menuBorder=1;
   mm_menu_0309135707_0.menuLiteBgColor='#336666'
   mm_menu_0309135707_0.menuBorderBgColor='#000000'

  window.mm_menu_0309140128_0 = new
  mm_menu_0309140128_0.addMenuItem("Belfast&nbsp;City&nbsp;Area"Northern&nbsp;Ireland");
   mm_menu_0309140128_0.hideOnMouseOut=true;
   mm_menu_0309140128_0.bgColor='#336666'
   mm_menu_0309140128_0.menuBorder=1;
   mm_menu_0309140128_0.menuLiteBgColor='#336666'
   mm_menu_0309140128_0.menuBorderBgColor='#000000'

mm_menu_0309140128_0.writeMenus();
}
>
<!--



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script language="JavaScript" src="mm_menu.js"></script>
</head>
<body onLoad="MM_preloadImages('images/home2.gif','images/company2.gif','images/contact2.gif','images/yboards2.gif','images/campaign2.gif','images/formats2.gif','images/register2.gif','images/links2.gif')">
<script language="JavaScript1.2">mmLoadMenus();</script>
<table width="702" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
  <!--DWLayoutTable-->
  <tr>
    <td width="602" height="123" rowspan="2" align="center" valign="bottom" bgcolor="#FFFFFF">
      <div align="left"><img src="graphic3.gif" width="90" height="123"></div>
      <div align="right"></div>
      <div align="right"></div></td>
    <td width="602" height="42" align="left" valign="bottom" bgcolor="#FFFFFF"><img src="topnavbar/toplogin.gif" width="600" height="40"></td>
  </tr>
  <tr>
    <td height="73" align="left" valign="bottom" bgcolor="#FFFFFF"><img src="banner.gif" width="600" height="80"></td>
  </tr>
  <tr align="center" valign="top">
    <td rowspan="2" bordercolor="#0099CC" bgcolor="#0099CC">&nbsp;</td>
    <td height="42" valign="bottom" bgcolor="#FFFFFF"><font color="#0033CC" size="5" face="Times New Roman, Times, serif">Welcome
      to the Look-See Login Page</font></td>
  </tr>
  <tr align="center" valign="top">
    <td bgcolor="#FFFFFF"><img src="RegBar.gif" width="600" height="20"></td>
  </tr>
  <tr align="center" valign="top">
    <td rowspan="5" bordercolor="#0099CC" bgcolor="#0099CC"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="center" valign="top"><a href="main.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Home','','images/home2.gif',1)"><img src="images/home1.gif" alt="Home" name="Home" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td><a href="CompanyInformation.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Company Information','','images/company2.gif',1)"><img src="images/company1.gif" alt="Company Information" name="Company Information" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td><a href="ContactUs.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Contact Us','','images/contact2.gif',1)"><img src="images/contact1.gif" alt="Contact Us" name="Contact Us" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td height="21"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Why Billboards?','','images/yboards2.gif',1)"><img src="images/yboards1.gif" alt="Why Use Billboards?" name="Why Billboards?" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td height="21"><a href="#" onMouseOut="MM_swapImgRestore();MM_startTimeout()" onMouseOver="MM_swapImage('Campaign Information','','images/campaign2.gif',1);MM_showMenu(window.mm_menu_0309133610_0,90,0,null,'Campaign Information')"><img src="images/campaign1.gif" alt="Campaign Information" name="Campaign Information" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td height="21"><a href="#" onMouseOut="MM_swapImgRestore();MM_startTimeout()" onMouseOver="MM_swapImage('Billboard Formats','','images/formats2.gif',1);MM_showMenu(window.mm_menu_0316175720_0,90,0,null,'Billboard Formats')"><img src="images/formats1.gif" alt="Billboard Format Information" name="Billboard Formats" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td height="21"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Register','','images/register2.gif',1)"><img src="images/register.gif" alt="Register" name="Register" width="90" height="21" border="0"></a></td>
        </tr>
        <tr>
          <td height="21"><img src="images/loginused.gif" alt="This page!" width="90" height="21"></td>
        </tr>
        <tr>
          <td height="21"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Links','','images/links2.gif',1)"><img src="images/links1.gif" alt="Links" name="Links" width="90" height="21" border="0"></a></td>
        </tr>
      </table></td>
    <td height="17" valign="bottom" bgcolor="#FFFFFF"><font color="#336699" size="2" face="Times New Roman, Times, serif">Please
      Enter Your Valid Email Address, Username and Password in the Fields Below</font></td>
  </tr>
  <tr align="center" valign="top">
    <td height="21" valign="bottom" bgcolor="#FFFFFF"><font color="#993300" size="2" face="Times New Roman, Times, serif">Note*
      All Fields Required</font></td>
  </tr>
  <tr align="center" valign="top">
    <td height="208" valign="top" bgcolor="#FFFFFF">
      <form method="POST" name="UserLoginForm" id="UserLoginForm" action="UserLogin.jsp">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr align="center" valign="middle">
           <td height="21" colspan="2">  
              <ul>
                <font color="#CC3300"> </font></ul></td>
          </tr>
          <tr align="center">
            <td height="13" colspan="2">
              <%-- Output a list of values that are invalid, if any --%>
              <font color="#FF0000">
              <jsp:getProperty name="Bean2" property="propertyStatusMsg"/>
              </font>
              <%-- List continues with propertyStatusDetails() call --%>
            </td>
          </tr>
          <tr align="center" valign="top">
            <td height="50" colspan="2"><font color="#CC3300">
              <% String[] details= Bean2.getPropertyStatusDetails();
                                            for(int j=0; j<details.length;j++) {
                                          out.print("<li>"+ details[j] +"</li>");
                                          }
                     %>
              </font></td>
          </tr>
          <tr align="center">
            <td height="11" colspan="2"> </td>
          </tr>
          <tr>
            <td height="21" align="center">Enter Email Address</td>
            <td><input name="emailAddress" type="text" id="emailAddress" value="<jsp:getProperty name="Bean2" property="emailAddress"/>" size="25%">
            </td>
          </tr>
          <tr>
            <td height="21" align="center">&nbsp;</td>
            <td width="50%">&nbsp;</td>
          </tr>
          <tr>
            <td width="50%" height="21" align="center">Enter Username</td>
            <td><input name="userName" type="text" id="Username2" value="<jsp:getProperty name="Bean2" property="userName"/>" size="25%">
            </td>
          </tr>
          <tr>
            <td height="21">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="21" align="center">Enter Password</td>
            <td><input name="passWord" type="password" id="passWord" value="<jsp:getProperty name="Bean2" property="passWord"/>" size="25%"></td>
          </tr>
          <tr>
            <td height="21">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="21" align="center"> <input type="submit" name="Submit" value="Submit"></td>
            <td align="center"><input name="Reset" type="button" id="Reset" value="Reset"
                  onClick="if (confirm('Are you sure you want to clear the form ?')) formCleanUp(document.UserLoginForm);"></td>
          </tr>
              <script language="JavaScript" type="text/JavaScript">
function formCleanUp(frm){
  var i
  for(i=0; i<frm.elements.length; i++) {
    var elt = frm.elements[i]
    var t = elt.type;
    switch(t) {
      case "text":
      case "hidden":
      case "password":
      case "textarea":
        elt.value="" ;
      break;
      case "checkbox":
        elt.checked=false;
      break;
      case "option":
        elt.selected=false;
      break;
    }
  }
}
</script>

        </table>
      </form></td>
  </tr>
  <tr>
    <td height="24" align="center" valign="bottom" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
  <tr valign="top">
    <td height="25" align="center" bgcolor="#FFFFFF"><font color="#336699" size="2" face="Times New Roman, Times, serif">Look-See&copy;2004</font></td>
  </tr>
</table>
</body>
</html>
0
 
Gar04Author Commented:
hey Kennethxu
i hope that you meant the jsp page and not the error page
if the latter, i am sorry for sending you the jsp
have you any more ideas as to what i need to do?
0
 
Gar04Author Commented:
this is the error message that i most frequently get:

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: /TMPdlv5nv3ktf.jsp(264,16) equal symbol expected
      at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)

0
 
kennethxuCommented:
the forward code should go right after <jsp:setProperty>
0
 
Gar04Author Commented:
so like this:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>

<jsp:useBean id="Bean2" class="com.ora.jsp.beans.userinfo.UserLoginBean" scope="request"/>
<jsp:setProperty name="Bean2" property="*"/><% if( Bean2.isValid() && Bean2.isUser() ) { %>
  <jsp:forward: page "main.jsp"/>
<% } %>

???
 i tried it and it gave the same error, but i guess that i am wrong!
gaz
0
 
kennethxuCommented:
what does isValid() and isUser() return, boolean?
0
 
kennethxuCommented:
which line of the jsp page that the error pointing to? can you post the line arround that number?
0
 
Gar04Author Commented:
yeah they have boolean return values
in the bean  isValid() looks like this:
public boolean isValid() {
       return StringFormat.isValidEmailAddr(emailAddress) && userName != null &&
              passWord != null;
       }
 


isUser() looks like this:

public boolean isUser() throws ClassNotFoundException, SQLException  {
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      // initialise connection, statement and result set variables
      Connection conn = null;
      PreparedStatement ps = null;
                                  try {
                  if (!isValid() ){
                 throw new SQLException( "invalid data - from UserRegBean.insertData" );
                 }
                 else {
      // make a connection to the BillBoardCompany Database
      conn = DriverManager.getConnection( "jdbc:odbc:BillboardCompany");
      // create statement object to interface with the SQL engine in database
        ps = conn.prepareStatement( "SELECT EmailAddress, Username, Password FROM UserRegInformation UserRegInformation WHERE"
        + "EmailAddress = ? AND Username = ? AND Password = ?)" );
              ps.setString( 1, emailAddress);
              ps.setString( 2, userName );
              ps.setString( 3, passWord );
              ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                      return true;
                  }
            else {
                     return false;
               }
                }
              
}
                  
finally {
        if( ps != null )
         try {ps.close(); }
         catch( Throwable t ) { t.printStackTrace(); }
         if( conn!=null)
        try {conn.close(); }
         catch( Throwable t ) { t.printStackTrace(); }
        }
            
    }      
0
 
kennethxuCommented:
it must be something else in the jsp page, try the login jsp that you have posted and let me the error is pointing to which line.
0
 
Gar04Author Commented:
the error doesn't seem to be pointing to any line
but here is the error:

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: /TMPkzut4v3ue5.jsp(4,16) equal symbol expected
      at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
      at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
      at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
      at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:169)
      at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:136)
      at org.apache.jasper.compiler.Parser.parseForward(Parser.java:517)
      at org.apache.jasper.compiler.Parser.parseAction(Parser.java:661)
      at org.apache.jasper.compiler.Parser.parseElements(Parser.java:803)
      at org.apache.jasper.compiler.Parser.parse(Parser.java:122)
      at org.apache.jasper.compiler.ParserController.parse(ParserController.java:199)
      at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
      at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
      at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      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:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
      at java.lang.Thread.run(Thread.java:479)

0
 
kennethxuCommented:
>> org.apache.jasper.JasperException: /TMPkzut4v3ue5.jsp(4,16) equal symbol expected
it is pointing to line 4 of TMPkzut4v3ue5.jsp
0
 
kennethxuCommented:
eh, here it is:
  <jsp:forward: page "main.jsp"/>
should be
  <jsp:forward: page="main.jsp"/>
you are missing the equal symble.
0
 
Gar04Author Commented:
hey well spotted
but i am still getting the same error!!
it does say equal sign??
what could it be ...
0
 
kennethxuCommented:
take the line number that's reported and see if there is any syntax error.
0
 
Gar04Author Commented:
<jsp:useBean id="Bean2" class="com.ora.jsp.beans.userinfo.UserLoginBean" scope="request"/>
<jsp:setProperty name="Bean2" property="*"/><% if( Bean2.isValid() && Bean2.isUser() ) { %>
  <jsp:forward page="main.jsp"/>
<% } %>

when i test the page, it opens the login.jsp and when i enter the data it returns the same error as above
0
 
kennethxuCommented:
could the error be in the forwarded page? you need to check the jsp page name in the error message
0
 
kennethxuCommented:
find the exact line in exact jsp file mentioned in the error message.
0
 
Gar04Author Commented:


so it reports
/UserLogin.jsp(4,16) equal symbol expected
i checked line 4  and there are no syntax errors that i can see
i am not sure what the 16 refers to cos it doesn't refer to any of the jsp

gaz
0
 
kennethxuCommented:
16 referes to the 16 the character in the line.
0
 
kennethxuCommented:
do a refresh, or delete your IE's temp files.
0
 
Gar04Author Commented:
i guess that it is the jsp if statement
why wouldn't it work....?

line 4 =  <jsp:setProperty name="Bean2" property="*"/><% if( Bean2.isValid() && Bean2.isUser() ) { %>
line 5 =  <jsp:forward page="Success.jsp"/>
line 6 =  <% } %>
0
 
kennethxuCommented:
you Bean2 is com.ora.jsp.beans.userinfo.UserLoginBean, make sure the both method are returning boolean.

you can test it by changing the code to:

<%=Bean2.isValid() %><p>
<%=Bean2.isUser() %><p>

also, try to break and add space to see if the line number changes:

<jsp:setProperty name="Bean2" property="*"/>
<% if( Bean2.isValid() && Bean2.isUser() ) { %>
<jsp:forward page="Success.jsp"/>
0
 
Gar04Author Commented:
this is what i tried and i got a bizarre error
i used some of the old code from UserRegBean and its method insertData
to produce the isUser() for UserLoginBean and this method seems to be using it
i am confused
can you shed any light?????

<jsp:setProperty name="Bean2" property="*"/>
<% if( Bean2.isUser() ) { %>
<jsp:forward page="Success.jsp"/>

javax.servlet.ServletException: invalid data - from UserRegBean.insertData
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
      at org.apache.jsp.TMPnp0qdv3xw2_jsp._jspService
0
 
Gar04Author Commented:
should i give the class a different package folder & recompile it??
this is weird
0
 
kuchingCommented:
ken, i admire you a lot....
0
 
Gar04Author Commented:
thanks Kuching
thats nice
0
 
Gar04Author Commented:
hey ken i
have a different error now that mucked about with the bean
any ideas?????

i have a : org.apache.jasper.JasperException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

i checked the sql but can't see ought??

      ps = conn.prepareStatement( "SELECT EmailAddress, Username, Password FROM UserRegInformation WHERE"
                    + "EmailAddress = ? AND Username = ? AND Password = ?)" );


                    ps.setString( 1, emailAddress);
                    ps.setString( 2, userName );
                    ps.setString( 3, passWord );
                    ResultSet rs = ps.executeQuery();
                  
                        if (rs.next()) {
                              
                              return true;
                        }
                              else {
                                 
                                 return false;
                                 
                              }
0
 
Gar04Author Commented:
hey ken
i spotted it eventually
there is no space between where and email and there is an extra )
well it works fine now
again you pulled me kicking and screaming through that one
you have the patience of a saint
i appreciate it
i will open another thread to award you more points
thanks
Gaz
0
 
objectsCommented:
Thanks for the points :-)

http://www.objects.com.au/staff/mick
0
 
kennethxuCommented:
I left my office so couldn't get back to you soon. glad to know your problem was resolved eventually.
don't worry about the points.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 23
  • 18
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now