• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what if jspbean creates an exception

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear all,

/*i accidentally pressed the ass new topic when i pressed the tab key.

sorry for misguiding u people*/

consider the code,

<%@ page errorPage='myerror.jsp'%>
<html>
<jsp:useBean id='myClass' class='CLass1'scope='request'>
<%
int i =0;/*Note here*/
%>
<jsp:setProperty name='myClass' property='i' value=<%=i%>/>
<jsp:getProperty name='myClass' property='i'/>
<html>

/*my bean class*/
class Class1
{
private int i ;
public void setI(int i)
{
this.i = 100/i; /*Arithematic exception when i = 0*/
}
public int getI()
{
return i;
}
}

i want the exception to be seen on the myerror.jsp page

how can i do it ?


please reply,

ajay vasudevan
scjp 1.4
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must create corresponding myerror.jsp
And define directive there
<%@ page isErrorPage="true" %>

Then you can use on this page "exception" implicit variable to get the details of the exception.
But remember: these directives override the error-page settings from the deployment descriptor
 
ajay vasudevan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Contrary to Mr Sergey has pointed out,

you will NOT get the exception object in the errorpage myerror.jsp as the exception becomes a null on the page.
(as i think the exception is set in the jsp:setProperty script)

but if the code to setting the bean is written within scriplets
it does work.

but i don't like using the scriplet in this case.

please can anyone guide me to a solution.


regards,

ajay vasudevan.
scjp 1.4
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use pageContext to reach JSP implicit variables in JSTL expressions

To clarify, here is the code i tested (yes, i tested it!)

TestClass1.java
-----------------------------------------
package com.test;
public class TestClass1 {
private int i;
public void setI(int i) {
this.i = 100 / i; /*Arithematic exception when i = 0*/
}
public int getI() {
return i;
}
}


test.jsp
-----------------------------------------------
<%@ page errorPage='myerror.jsp'%>
<html>
<jsp:useBean id='myClass' class='com.test.TestClass1' scope='request'/>
<%
int i =0;/*Note here*/
%>
<jsp:setProperty name='myClass' property='i' value='<%=i%>'/>
<jsp:getProperty name='myClass' property='i'/>
<html>

myerror.jsp
-----------------------------------------------
<%@ page isErrorPage="true" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
Hi! <c ut value="${pageContext.exception}"/>



Hope, it helps
 
reply
    Bookmark Topic Watch Topic
  • New Topic