• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1819
  • Last Modified:

Array Index out of bounds exception?

I'm getting an array index  out of bounds exception, I'm not sure what the problem is, I'm hoping a fresh pair of eyes could give me a few clues.
SERVLET CODE
 
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package controller;
 
import group.user;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 *
 * @author noah
 */
public class login extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       user user = new user();
 
 
        String email= request.getParameter("user");
        String password= request.getParameter("password");
 
 
        if(user.login(email, password)==true)
        {
Cookie userCookie =  new Cookie("user",email);
userCookie.setMaxAge(86400);
userCookie.setPath("/");
response.addCookie(userCookie);
 
 
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/home.jsp");
dispatcher.forward(request, response); // I GET THE ARRAY OUT OF BOUNDS EXCEPTION
//HERE
 
        }else{
 
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/results.jsp");
dispatcher.forward(request, response);
 
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    } 
 
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 
 
    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
 
    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
 
}
 
 
 
 
 
CLASS WITH METHOD USED IN SERVLET
 
 
 
 
public boolean login(String email,String password){
    sqlData="SELECT email, password FROM USER WHERE email='"+email+"'";
    String holdemail="";
    String holdpassword="";
    boolean status=true;
 
    //get information from database
try {
Class.forName("sun.jdbc.odbc.JdbcOdcbDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(user.class.getName()).log(Level.SEVERE, null, ex);
}
    try{
 
Connection connection = DriverManager.getConnection(this.data,"","");
Statement statement= connection.createStatement();
ResultSet record = statement.executeQuery(sqlData) ;
if(record.next())
 
{
 
holdemail = record.getString(1);
holdpassword = record.getString(2);
 
}else return false;
 
record.close();
}
 catch(SQLException s)
{
System.out.println("SQL Error:"+s.toString()+""+s.getErrorCode()+""+s.getSQLState());
}
 
 
 
if(holdemail.equals(email) && holdpassword.equals(password))
{
 
status=true;
 
 
}else
{
status=false;
}
 
 
return status;
}

Open in new window

0
AlexanderMaxwell
Asked:
AlexanderMaxwell
  • 7
  • 6
1 Solution
 
rrzCommented:
Please show us the full error message and stack trace.
0
 
AlexanderMaxwellAuthor Commented:
The log message is null.
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdcbDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:992)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1489)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at group.user.login(user.java:91)
        at controller.login.processRequest(login.java:39)
        at controller.login.doPost(login.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
ApplicationDispatcher[/cart] PWC1231: Servlet.service() for servlet jsp threw exception
java.lang.ArrayIndexOutOfBoundsException: 1
        at org.apache.jsp.home_jsp._jspService(home_jsp.java from :61)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:855)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:542)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:474)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:366)
        at controller.login.processRequest(login.java:48)
        at controller.login.doPost(login.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
StandardWrapperValve[login]: PWC1406: Servlet.service() for servlet login threw exception
java.lang.ArrayIndexOutOfBoundsException: 1
        at org.apache.jsp.home_jsp._jspService(home_jsp.java from :61)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:855)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:542)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:474)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:366)
        at controller.login.processRequest(login.java:48)
        at controller.login.doPost(login.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
0
 
rrzCommented:
>java.lang.ArrayIndexOutOfBoundsException: 1
>        at org.apache.jsp.home_jsp._jspService(home_jsp.java from :61)
Please look in Tomcat's work folder for home_jsp.java
What is on and around line 61   ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AlexanderMaxwellAuthor Commented:
I'm not using tomcat, I'm using glassfish2 with Netbeans.
0
 
rrzCommented:
Please post home.jsp,then.
0
 
AlexanderMaxwellAuthor Commented:
Here you go
<%@page import="group.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
 
<html>
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CARLAND</title>
</head>
 
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">
<%
 
Cookie[] cookies = request.getCookies();
Cookie cookie= cookies[1];
%>
 
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="img/topbkg.gif">
  <tr>
    <td width="50%"><img src="img/85073_banner.jpg" width="728" height="75"></td>
    <td width="50%">
      <p align="right"><img border="0" src="img/topright.gif" width="327" height="66"></td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="img/blackline.gif">
 <tr>
 <td width="100%">  <font color="#B8C0F0" face="Arial" size="2"><b> &nbsp;&nbsp;<a href="home.jsp">Home</a> &nbsp; |&nbsp;&nbsp;<a href="advanceSearch.jsp">Advance Search</a>&nbsp; |&nbsp;&nbsp;<a href="catalog">Catalog</a>&nbsp;|&nbsp;&nbsp; Hello: <%=cookie.getValue()%> !</b></font></td>
 </tr>
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                                    
<form name="search" action="search">
&nbsp;&nbsp;&nbsp;&nbsp; <b>SEARCH:</b><input type="text" name="key" value="" />
<input type="submit" value="Submit" name="button" />
</form>
 
               
    
 
 
 
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="img/botline.gif">
  <tr>
    <td width="100%"><img border="0" src="img/botline.gif" width="41" height="12"></td>
  </tr>
</table>
 
 
</body>
 
</html>

Open in new window

0
 
rrzCommented:
>Cookie cookie= cookies[1];  
How many cookies are there ?  
try  
Cookie cookie= cookies[0];
0
 
AlexanderMaxwellAuthor Commented:
I think it works, give me a moment to test.
0
 
AlexanderMaxwellAuthor Commented:
That  solved the problem, thanks so much. However, I have another small question.


when I use  "cookie.getValue()" it returns gibberish and not the value, which would be an email address, what would cause that?
0
 
rrzCommented:
Maybe that is an encoding problem.  
0
 
AlexanderMaxwellAuthor Commented:
what do you mean by encoding problem?
0
 
AlexanderMaxwellAuthor Commented:
never mind...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now