Solved

using int value returned by a javabean

Posted on 2004-04-26
7
299 Views
Last Modified: 2010-04-01
well, i'm new to jsp & javabean development and been having some what i consider as should be simple problems.

i''ve created a javabean that checks and returns an integer value of what the user did.  it checks for user's id & password and depending on the user's correct info level, i'm returning a number.  so 0 = no match, 1 = user id match, 2 = user id match but password wrong, 3 = all match.

in my jsp, i'm just trying to use the value that's returned.

well, i originally tested the bean just passing back true or false.  so if the user's id matched, return true.  that worked fine.  now i''ve changed everything to use these int and it just doesn't seem to do anything but bomb.  i tried to use Integer.parseInt but didn't do anything.

can you help me out?

as i'm sure it's usually the case here, i really need this working asap.

some code:

in javabean:
        public int existsUser (String strEmail, String strPassword) {
           
            String url = "jdbcdriver";
            Connection con;
            Statement stmt;
            String query = "select UserID, Password from Authorization where Email = '" + strEmail + "'";
                // 0= user does not exist, 1 = user exists but did not match password,
                //2 = user exists, but password wrong, 3 = all matched & good
                int intHaveRS = 0;
                String strUID = "";
                String strPass = "";
      
            try {
                  Class.forName("com.mysql.jdbc.Driver");
      
            } catch(java.lang.ClassNotFoundException e) {
                  System.err.print("ClassNotFoundException: ");
                  System.err.println(e.getMessage());
                  return 0;
            }

            try {
                  con = DriverManager.getConnection(url, "iars_bears", "iars_bears");
      
                  stmt = con.createStatement();
      
                  ResultSet rs = stmt.executeQuery(query);
      
                  if (rs.next()) {
                        strUID = rs.getString("UserID");
                                strPass = rs.getString("Password");
                                intHaveRS = 1;
                                if (strPassword.equals(strPass)) {
                                    intHaveRS = 3;
                                } else {
                                    intHaveRS = 2;
                                }
                  } else {
                        setUID(null);
                                intHaveRS = 0;
                  }
      
                  stmt.close();
                  con.close();
      
            } catch(SQLException ex) {
                  System.err.println("SQLException: " + ex.getMessage());
                  return 0;
            }

            return intHaveRS;
           
        }

and jsp:
<%@page import="java.lang.*, java.io.*" %>
<jsp:useBean id="Authorization" class="msk.Authorization" />
<%
int iUExist=0;

if (request.getParameter("btnSubmit") != null)  {
    iUExist = Authorization.existsUser((request.getParameter("txtEmail")),(request.getParameter("txtPassword")));
    if (iUExist > 0) {
        out.print("this user exists! " + iUExist);
    } else {
        out.print("this user DOES NOT exists!");
    }
}

%>

<p>Welcome!</p>
<form name="frmAdmLogin" method="post" action="">
  <p>user email
    <input type="text" name="txtEmail">
  </p>
  <p>user password
    <input type="text" name="txtPassword">
  </p>
  <p>
    <input type="submit" name="btnSubmit" value="Submit">
    <input type="reset" name="btnCancel" value="Cancel">
  </p>
</form>
</body>
0
Comment
Question by:mskim100
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10923042
what's the error message?
0
 

Author Comment

by:mskim100
ID: 10923251
this is what i get

mskim100
=========================

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: msk.Authorization.existsUser(Ljava/lang/String;Ljava/lang/String;)I
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
      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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
      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.StandardContext.invoke(StandardContext.java:2417)
      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:193)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
      at java.lang.Thread.run(Thread.java:534)


root cause

javax.servlet.ServletException: msk.Authorization.existsUser(Ljava/lang/String;Ljava/lang/String;)I
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
      at org.apache.jsp.admLogin_jsp._jspService(admLogin_jsp.java:108)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
      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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
      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.StandardContext.invoke(StandardContext.java:2417)
      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:193)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
      at java.lang.Thread.run(Thread.java:534)
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10923301
to avoid the obvious, you've re-compiled your bean and restarted your server right?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:mskim100
ID: 10923328
i've recompiled my bean but it's a remote server and i can't restart.  i did reload my class tho.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 500 total points
ID: 10923385
you have to restart... it's probably using your old bean which is why when you try to assign the int value it bombs... existsUser is probably still returning a boolean.
0
 

Author Comment

by:mskim100
ID: 10923414
so as far as you can see, i should be able to use my int that's returned from my bean?  well, i'll have to ask someone to restart then.  i'll let you know what happens when i get it restarted.

mskim100
0
 

Author Comment

by:mskim100
ID: 10923680
restart worked!

thanks!

mskim100
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audiā€¦

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question