aspose file tools*
The moose likes Servlets and the fly likes org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8 " Watch "org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8 " New topic
Author

org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8

Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
hello , friends .
I am getting exception when i am using Request Dispatcher to forward request and response to the JSP from servlet.
The exception is as below,

org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8

please, help me as soon as possible..
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

What is the logic you have in servlet? You have any arrays accessed inside the JSP? Please provide MoreDetails


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
Vijitha Kumara wrote:What is the logic you have in servlet? You have any arrays accessed inside the JSP? Please provide MoreDetails


this is my code as below..
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author rahul
*/
public class servlet 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
*/
String id,password,sql=null;
Statement st=null;
RequestDispatcher view=null;
ResultSet rs=null;
Object str[]= new Object[10];
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession(true);
try {
id=request.getParameter("id");
password=request.getParameter("password");
out.println(id);
if((id=="")||(password=="")){
view=getServletContext().getRequestDispatcher("/login.jsp");
view.forward(request, response);
}
DBConnection obj=new DBConnection();
st=obj.fun();
sql="select * from Table1 where id='"+id+"' and password='"+password+"'";
rs=st.executeQuery(sql);
while(rs.next()){
str[0]=rs.getObject("id");
str[1]=rs.getObject("name");
str[2]=rs.getObject("address");
str[3]=rs.getObject("contactNo");
str[4]=rs.getObject("emailID");
str[5]=rs.getObject("course");
str[6]=rs.getObject("branch");
str[7]=rs.getObject("password");
}

session.setAttribute("id", str[0]);
session.setAttribute("name", str[1]);
session.setAttribute("address", str[2]);
session.setAttribute("contactNo", str[3]);
session.setAttribute("emailID", str[4]);
session.setAttribute("course", str[5]);
session.setAttribute("branch", str[6]);
session.setAttribute("password", str[7]);
view =request.getRequestDispatcher("info.jsp");
view.forward(request, response);

/* TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet servlet at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
*/
} catch (Exception ex) {
out.println(ex);
ex.printStackTrace(out);
} finally {
out.close();
}
}

// <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>

}

I am getting error at high lighted text
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Please use code tags when you are posting code. Un-formatted code is very hard to read. Cannot see anything wrong in the servlet (assuming the method calls etc... should for work there) except all the code (including DB access,business logic etc.. ) lies inside the servlet. Can you show us your JSP?
Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
Vijitha Kumara wrote:Please use code tags when you are posting code. Un-formatted code is very hard to read. Cannot see anything wrong in the servlet (assuming the method calls etc... should for work there) except all the code (DB access,business logic etc.. ) all lies there. Can you show us your JSP?



Yes..

i can..
the jsp code as below..



<%--
Document : info
Created on : Feb 27, 2009, 11:09:40 AM
Author : rahul
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java" session="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Information Page</title>
<style type="text/css">
h2.xyz
{
position:absolute;
left:520px;
}
h2.abc{
position:absolute;
left:320px;
}
</style>
</head>
<body bgcolor="blue" >
<h1>Hello, ${param.id}</h1>
<form action="update.jsp" method="post">
<%
String str[]=new String[8];
str[0]=(String)session.getAttribute("id");
str[1]=(String)session.getAttribute("name");
str[2]=(String)session.getAttribute("address");
str[3]=(String)session.getAttribute("contactNo");
str[4]=(String)session.getAttribute("emailID");
str[5]=(String)session.getAttribute("course");
str[6]=(String)session.getAttribute("branch");
str[7]=(String)session.getAttribute("password");
str[8]=(String)session.getAttribute("image");


%>
<h2 class="abc">User ID:</h2>
<h2 class="xyz"> <%= str[0]%></h2>


<h2 class="abc">User Name:</h2>
<h2 class="xyz"> <%= str[1]%></h2>


<h2 class="abc">User Address:</h2>
<h2 class="xyz"><%= str[2]%></h2>


<h2 class="abc">User Contact NO.:</h2>
<h2 class="xyz"> <%= str[3]%></h2>


<h2 class="abc">User Email ID:</h2>
<h2 class="xyz"> <%= str[4]%></h2>


<h2 class="abc">User Course:</h2>
<h2 class="xyz"> <%= str[5]%></h2>


<h2 class="abc">User Branch:</h2>
<h2 class="xyz"> <%= str[6]%></h2>


<h2 class="abc">User Password:</h2>
<h2 class="xyz">${param.password}</h2>


<h2 class="xyz"><input type="submit" value="Update" /></h2>


</form>
</body>
</html>
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838



Here's what's wrong. You are setting the value for the 9th cell while you have set it to have only 8 cells. For str[8] to work you need to have the array initialized as "new String[9]".
Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
Vijitha Kumara wrote:

Here's what's wrong. You are setting the value for the 9th cell while you have set it to have only 8 cells. For str[8] to work you need to have the array initialized as "new String[9]".



Thank you very much..

there is also another error ..

I am gettin java.lang.NullPointerException java.lang where I am enter wromg id and pasword at login page...

the code of the login page is as below..



<%--
Document : login
Created on : Feb 27, 2009, 10:57:24 AM
Author : rahul
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Login Page</title>
<style type="text/css">
h2.pos_abs
{
position:absolute;
left:450px;
}
h2.abc{
position:absolute;
left:320px;
}


</style>
</head>
<body bgcolor="blue" >
<h1>Hello World!</h1>
<form action="servlet" method="post">
<h2 class="abc" >User ID:</h2>
<h2 class="pos_abs"><input type="text" name="id" value="" /></h2>


<h2 class="abc"> Password:</h2>
<h2 class="pos_abs"><input type="password" name="password" value="" /></h2>


<h2 class ="pos_abs"><input type="submit" value="Login" /></h2>


</form>
<h2 class="pos_abs">Register Now!!!</h2>
</body>
</html>



Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

plaese give me your email ID , so I can send you also mail my problem...there is also another error ..


You can always post any problem here at an appropriate forum, So somebody there will help you, not just me.

Coming to your next problem. You have highlighted an HTML part, in the servlet you will have to check for null or empty conditions before trying to use them. That may be causing the exception. If that's not work you should give more details for people to help you.
Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
Vijitha Kumara wrote:
plaese give me your email ID , so I can send you also mail my problem...there is also another error ..


You can always post any problem here at an appropriate forum, So somebody is there will help you not just me.

Coming to your next problem. You have highlighted an HTML part, in the servlet you will have to check for null or empty conditions before trying to use them. That may be causing the exception. Is that's not work you should give more details for people to help you.




ok.. It is solved..

Now I want to pop up alert box when some enter wrong password or id using java script..

can you help me out...

and again thank you for your reply...


Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

aditya bhaskaruni,
Your post was moved to a new topic.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8