Solved

using int value returned by a javabean

Posted on 2004-04-26
7
297 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
password protect pdf 11 76
stateless EJB with glassfish 2 73
java cigar challenge 58 210
ejb on wildfly 5 19
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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