Global Exceptions in Struts

Hi All,
When ever there is an error I need to handle the exceptions gracefully. Since I'm using struts frame work I'm using global-exceptions declarative.
Here is the struts-config.xml where I have included <global-exceptions>
<global-exceptions>
<exception handler="com.hp.chrs.action.ActionExceptionHandler"
type="java.lang.Exception"
key="global.error.message "
path="/jsp/chrs_error.jsp" />
</global-exceptions>
I have written ActionExceptionHandler.java class which is the subclass of ExceptionHandler. In execute function of this I'm logging the error then forwarding it to chrs_error.jsp.
public ActionForward execute(Exception ex, ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {
System.out.println ("Inside execute of ActionExceptionHandler");
logError(ex);
//forward to the jsp
ActionForward forward =
super.execute(ex, ae, mapping, formInstance, request, response);
When ever an error occurs chrs_error.jsp is displayed. But it is not going to ActionExceptionHandler.java class.
What my unerstanding is whenever error occurs it should go to ActionExceptionHandler and then display chrs_error.jsp.
Any inputs are welcome
Thanks in Advance

Most probably its the wrond struts version...you cannot use message resources in struts i.0, might want to change the head of the struts-config.xml to
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

Similar Messages

  • Global Exception in Struts

    Hi All,
    When ever there is an error I need to handle the exceptions gracefully. Since I'm using struts frame work I'm using global-exceptions declarative.
    Here is the struts-config.xml where I have included <global-exceptions>
    <global-exceptions>
    <exception handler="com.hp.chrs.action.ActionExceptionHandler"
    type="java.lang.Exception"
    key="global.error.message"
    path="/jsp/chrs_error.jsp" />
    </global-exceptions>
    I have written ActionExceptionHandler.java class which is the subclass of ExceptionHandler. In execute function of this I'm logging the error then forwarding it to chrs_error.jsp.
    public ActionForward execute(Exception ex, ExceptionConfig ae,
    ActionMapping mapping,
    ActionForm formInstance,
    HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException {
    System.out.println("Inside execute of ActionExceptionHandler");
    logError(ex);
    //forward to the jsp
    ActionForward forward =
    super.execute(ex, ae, mapping, formInstance, request, response);
    When ever an error occurs chrs_error.jsp is displayed. But it is not going to ActionExceptionHandler.java class.
    What my unerstanding is whenever error occurs it should go to ActionExceptionHandler and then display chrs_error.jsp.
    Any inputs are welcome
    Thanks in Advance

    No there isn't a global exception handler in JSF. At least none that I've ever heard of or run across. This is something I think JSF dropped the ball on. Maybe in a future release?
    I'm afraid you'll have to get creative with error processing. It's tricky with JSF.
    The way I did it in my application was to create error pages (as you mentioned). I configured the web.xml to redirect to these error pages if there was an uncaught exception. There are some serious limitations when you forward to a JSF page like this though. First, you need to make your error page have f:subview tags instead of f:view. Then, I couldn't get commandLink or commandButton to work right. The action method never got executed!
    You may have already seen some discussions about this. If not, dig around in the forums and you'll find a few good tips.
    CowKing

  • Strut - global exceptions

    does anyone know the syntax for global exceptions in struts?
    thnx,
    sunsons

    Global Exceptions are configured with <global-exceptions> in the struts-config.xml file.
    A <global-exceptions> configures the global handling of exceptions thrown by Actions to mappable resources using an application-relative URI path. This can be a specific page designed to handle this exception.

  • Exception in global forwards in strut-config.xml

    Hi friends,
    i am doing a global forward and i am getting the following exception. without global forward in strut-config.xml it works fine.exception
    javax.servlet.ServletException: Cannot find global ActionForward for name welcome
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
         org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:76)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    javax.servlet.jsp.JspException: Cannot find global ActionForward for name welcome
         org.apache.struts.taglib.logic.ForwardTag.doEndTag(ForwardTag.java:142)
         org.apache.jsp.test_jsp._jspx_meth_logic_forward_0(org.apache.jsp.test_jsp:93)
         org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:64)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)my struts-config.xml is
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
              "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
    <struts-config>
    <!-- ========== Global Forward Definitions ============================== -->
      <global-forwards>   
      <forward name="welcome" path="/LPCIndex/doit.do" redirect="true"/>
      </global-forwards>
      <!-- ========== Action Mapping Definitions ============================== -->
      <action-mappings>   
    <action
         path="/doit"
         type="com.hsbc.lpcintex.LPCIntexAction">
         <forward name="success" path="/index.jsp"/>
    </action>
      </action-mappings>
    </struts-config>my web.xml
    is
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
      Copyright 2004 The Apache Software Foundation
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    <!-- JSPC servlet mappings start -->
    <!-- The Welcome File List -->
         <welcome-file-list>
              <welcome-file>test.jsp</welcome-file>
         </welcome-file-list>
         <session-config>
              <session-timeout>0</session-timeout>
         </session-config>
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <!-- JSPC servlet mappings end -->
    </web-app>and my jsp code is
    <%@ page language="java" import="com.hsbc.lpcintex.*" import="java.io.*"%>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <html>
    <body>
    <logic:forward name="welcome"/>
    </body>
    </html>any help please
    thanks
    R

    its done by adding
    <load-on-startup>2</load-on-startup>to web.xml

  • How to handle exception in struts

    i am using global exception to pass to a page that shows an error message.
    I also want to pass the actual error message to that page is that possible
    through the struts config
    <global-exceptions>
    <!-- global exception handler -->
    <exception
    key="global.message"
    type="java.lang.Exception"
    path="Errors.jsp"/>
    </global-exceptions>

    i am using global exception to pass to a page that shows an error message.
    I also want to pass the actual error message to that page is that possible
    through the struts config
    <global-exceptions>
    <!-- global exception handler -->
    <exception
    key="global.message"
    type="java.lang.Exception"
    path="Errors.jsp"/>
    </global-exceptions>

  • Global Exception Handling

    How to set up global exception handling to provide user friendly messages to user?
    AFAIK there is no real global exception handing available for now in ADF. So I need some "tutorials" about exception handling in:
    - Model
    - Controller
    - View
    Thx
    Regards
    Zmeda

    refer this
    http://blogs.oracle.com/groundside/entry/adventures_in_adf_logging_part
    controller
    http://blogs.oracle.com/jdevotnharvest/entry/extending_the_adf_controller_exception_handler
    http://andrejusb.blogspot.com/2011/03/exception-handler-for-method-calls_19.html
    http://my.safaribooksonline.com/book/databases/oracle/9780071622547/introduction-to-oracle-adf-task-flows/ch04lev1sec7
    http://my.safaribooksonline.com/book/databases/oracle/9780071622547/working-with-unbounded-and-bounded-oracle-adf-task-flows/169

  • Query regarding Declarative exceptions in struts

    Hi all,
    I am using decalartive exceptions in struts,
    My struts-config.xml is as follows -
    <action
    path="/tryexception"
    <exception
    type="hansen.playground.MyException1"
    key ="errors.exception1"
    handler="hansen.playground.MyHandler"
    path="/error.jsp"/>
    </action>
    Currently i am displaying the error message in my error.jsp page by getting the value from the session.
    The code is as follows -
    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="org.apache.struts.*" %>
    <%
    Enumeration paramNames = request.getAttributeNames();
    while (paramNames.hasMoreElements()) {
    String name = (String) paramNames.nextElement();
         if (name.equals("errorMessage")){
              Object values = request.getAttribute(name);
              out.println("<br> " + name + ":" + values);
    %>
    This works fine and the error message is diplayed.
    My question is there any other way to display the error message in the jsp page without getting it from the session.
    Any suggestions will be appreciated
    Thanks,

    You could simply POST the data as opposed to using GET. Though it doesn't encode/ encrypt the data, but simply adds the parameters into the body of the request. If someone were to look at your requests, they'd be able to see this data.
    As for actually hiding it through encryption, you could get JavaScript libraries to do this on form submit but I doubt you'd need that much security. You could also try base64 encoding for a simpler approach.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • exception in struts-config.xml

    hi all
    I added a validate method in my struts action form.
    public ActionErrors validate(........)
    ActionErrors errors=new ActionErrors();
    errors.add("symbol",new ActionError("add.key.like");
    and in jsp form I used <html:errors/> if any error occured it will display it from resourcebundle from the key...
    but my actual doubt is how the above procedure is different from
    <exception> in struts-config.xml
    thanks
    srikanth

    Need Help!
    I use weblogic8.1 and
    the entry is http://localhost:7001/interactive/LogonAction.do?method=initLogon
    I don't know why it execute the initLogon() method but can't return to the page.

  • Global Exception Class

    Hi,
    I have a global exception class which is inherited from already existing exception class.
    I would like to use this class to raise different exceptions.
    How to use this global exception class to raise exceptions with different descriptions?
    can anybody explain or send a material on this?
    Thanks in advance...
    Sreenivas Reddy

    I guess you have little misunderstanding of the Exception concept.
    You have to RAISE the exception from any processing block (Subroutine, Method etc.) and CATCH the exception in where you call the subroutine.
    Check this example. In this example, I am raising the exception from the method DEVIDE of the class LCL_TEST. Now, I call this method DEVIDE in the START-OF-SELECTION block. So, here I need to catch this raised exception by the DEVIDE method. In my example I have used the exception class ZCX_GEN_EXC, you may have to replace it with your exception class ZCX_SAMPLE_EXCEPTION.
    CLASS lcl_test DEFINITION.
      PUBLIC SECTION.
        METHODS devide
          IMPORTING
            n1 TYPE i
          CHANGING
            n2 TYPE i
          RAISING
            zcx_gen_exc.
    ENDCLASS.                    "lcl_test DEFINITION
    START-OF-SELECTION.
      DATA: lo_test TYPE REF TO lcl_test,
            lo_exc  TYPE REF TO zcx_gen_exc,
            lf_n1   TYPE i,
            lf_n2   TYPE i.
      CREATE OBJECT lo_test.
      lf_n1 = 0.
      lf_n2 = 10.
      TRY.
          CALL METHOD lo_test->devide
            EXPORTING
              n1 = lf_n1
            CHANGING
              n2 = lf_n2.
    * catching the exception
        CATCH zcx_gen_exc INTO lo_exc.
          MESSAGE lo_exc->wf_etext TYPE 'I'.
      ENDTRY.
    CLASS lcl_test IMPLEMENTATION.
      METHOD devide.
        IF n1 = 0.
          RAISE EXCEPTION TYPE zcx_gen_exc
            EXPORTING
              wf_etext = 'Exception occured'
              wf_mtype = 'E'.
        ELSE.
          n2 = n2 / n1.
        ENDIF.
      ENDMETHOD.                    "devide
    ENDCLASS.                    "lcl_Test IMPLEMENTATION
    Regards,
    Naimesh Patel

  • Global Exception Handler

    Hello,
    I've implemented the Global Exception Handler how is saying at http://www.adobe.com/devnet/flex/articles/global-exception-handling.html
    Some errors are being catched by it, and others not.
    I looked at another thread here, but for him, the Debug Dialog was not appearing because another place was catching the exception for him.
    There are some way to catch all errors in just on place?
    I need this, because sometimes in production happen errors that we didn't find in development, but stills there.
    The SDK is 4.1 and minimum Flash Player for the applications is 10.1.
    Regards,
    Fredy.

    How to reproduce the error not being catched.
    Main Application:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                     xmlns:s="library://ns.adobe.com/flex/spark"
                                     xmlns:mx="library://ns.adobe.com/flex/mx"
                                     minWidth="955"
                                     minHeight="600"
                                     xmlns:views="views.*"
                      applicationComplete="onApplicationComplete()">
              <s:layout>
                        <s:VerticalLayout />
              </s:layout>
              <fx:Script>
                        <![CDATA[
                                  import com.adobe.ac.logging.GlobalExceptionHandler;
                                  import com.adobe.ac.logging.LogHandlerAction;
                                  private var globalExceptionHandler:GlobalExceptionHandler;
                                  private function onApplicationComplete():void {
                                            globalExceptionHandler = new GlobalExceptionHandler();
                                            globalExceptionHandler.preventDefault = true;
                                            var lha:LogHandlerAction = new LogHandlerAction();
                                            globalExceptionHandler.handlerActions = [];
                                            globalExceptionHandler.handlerActions.push(lha);
                        ]]>
              </fx:Script>
              <mx:ViewStack id="vs" creationPolicy="none">
                        <views:FirstView  />
                        <views:SecondView />
              </mx:ViewStack>
              <s:Button label="Call Second View" click="vs.createDeferredContent()"/>
    </s:Application>
    First View:
    <?xml version="1.0" encoding="utf-8"?>
    <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
                         creationComplete="onCreationComplete()">
              <fx:Script>
                        <![CDATA[
                                  import mx.rpc.remoting.RemoteObject;
                                  private function onCreationComplete():void {
                                            trace("First Created!");
                        ]]>
              </fx:Script>
    </s:NavigatorContent>
    Second View:
    <?xml version="1.0" encoding="utf-8"?>
    <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
                                                      xmlns:s="library://ns.adobe.com/flex/spark"
                                                      xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
                                                      creationComplete="onCreationComplete()">
              <fx:Script>
                        <![CDATA[
                                  import mx.rpc.remoting.RemoteObject;
                                  private function onCreationComplete():void {
                                            trace("Second View created!");
                                            var ro:RemoteObject;
                                            ro.destination = "";
                        ]]>
              </fx:Script>
    </s:NavigatorContent>
    Regards,
    Fredy.

  • What is a global Action in Struts?

    What is a global Action in Struts?
    if any body have any idea about it then plz tell me ab this...
    Thanx

    well some one ask me this question in an Interview?
    what is the difference between Global Action anc Global Forward?
    nither i heard ab Global Action ...nor i use it...so i told him a do not have any info ab it...

  • Calling EJBs from Global Exception Handler

    Hi, I'm using Weblogic Workshop 8.1.4.
    I have a JPF which calls a EJB to set a lock flag (to prevent the JPF being executed twice at the same time.)
    I want to reset the lock flag in the global exception handler, however, if I call an EJB (Entity or Session) in a perform node in the exception handler, I get a NullPointerException.
    Is this because it's being called in the exception handler? Is there any way to work around this (without building a POJO which does all the persistance logic and SQL calling manually?)
    Thanks.

    You can redirect stdout to wherever you want by using
    System.setOut(PrintStream out). Also, you can give
    printStackTrace a PrintStream.
    hth,
    mI think to solve this problem you should call System.setErr(PrintStream err);

  • Global exception handler not being called

    Hi,
    I have a wli process that has a global excepton handler. One of the controls throws a NullPointerException but it is not being handled by the group exception handler nor the global exception handler.
    Does anyone have any idea what may be causing this behaviour?
    Thanks,
    Dale

    I have discovered that using -memalign=Ns with N greater than 1 does not work for me. For example, if I remove a VME card from the system and try to use an unsigned short pointer to access a 16-bit register in the card's vacated VME address space, my signal handler gets called when I compile the code with N=1, but for any other N, my handler is ignored and my program cores.
    Unfortunately, using N=1 causes other code that works with higher N to fail. I have one VME card where I need to access a register as a 16-bit read. The code the compiler generates to access the unsigned short pointer value results in two single-byte load instructions - this causes the device to cry foul and as a result, the driver raises SIGBUS, which my program handles. For higher N, the compiler generates one two-byte load instruction, and the device is happy to send back the data.
    So it would appear there is some kind of problem with -xmemalign=Ns for N > 1. It seems like the SIGBUS handler typically imployed by the compiler to handle the misalignment problems when -xmemalign=Ni is used is being invoked.
    Any other ideas?

  • Global exception handling (Web Applications)

    Hi,
    I want to capture all run time exceptions and store them into a log file.
    I have used uncaught error event handler for catching all such run time exceptions.
    Application has various components and I have manualy introduced few run time exceptions at various places
    I was able to capture these uncaught exceptions only at very few places and even this was not consistent.
    Any help will be greatly appreciated.
    Thanks,
    Abhishek.

    If you have multiple SWFs, you may need information in this post: http://blogs.adobe.com/aharui/2011/04/catching-uncaughterror-in-flex-modules.html

  • How to handle the global exception at servlet filter?

    I cannot redirect the page or add the error message to faces context after the rollback. How do I can show the error to the client?
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
    UserTransaction utx = null;
    try {
    InitialContext ctx = new InitialContext();
    utx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    utx.begin();
    EntityManager em = EntityManagerUtil.getEntityManager();
    chain.doFilter(request, response);
    em.flush();
    utx.commit();
    em.clear();
    }catch(Throwable t) {
    logger.error(t, t);
    try {
    utx.rollback();
    }catch(SystemException se) {
    logger.error(se, se);
    } finally {
    EntityManagerUtil.closeEntityManager();
    }

    If I send the error code, it will throw the following exception because the response is committed.
    java.lang.IllegalStateException
    java.lang.IllegalStateException
    at org.apache.coyote.tomcat5.CoyoteResponseFacade.sendError(CoyoteResponseFacade.java:433)
    at mo.gov.safp.eform.web.filter.EntityManagerFilter.doFilter(EntityManagerFilter.java:57)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
    Should I solve it?
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
    UserTransaction utx = null;
    try {
    // Define the request and the response encoding.
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    InitialContext ctx = new InitialContext();
    utx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    utx.begin();
    EntityManager em = EntityManagerUtil.getEntityManager();
    chain.doFilter(request, response);
    em.flush();
    utx.commit();
    em.clear();
    }catch(Throwable t) {
    logger.error(t, t);
    try {
    utx.rollback();
    }catch(SystemException se) {
    logger.error(se, se);
    ((HttpServletResponse)response).sendError(500);
    }

Maybe you are looking for