Struts 2 global exception handling tutorial

            In this tutorial we'll explore how to enable the Struts 2 framework to handle any uncaught exceptions generated by a web application. Struts 2 provides robust exception handling, including the ability to automatically log any uncaught exceptions and redirect the user to a error web page.

            Using the Struts 2 framework you can specify in the struts.xml how the framework should handle uncaught exceptions. The handling logic can apply to all actions (global exception handling) or to a specific action. Let's first discuss how to enable global exception handling.

            To enable global exception handling you need to add two nodes to struts.xml: global-exception-mapping and global-results. For example examine struts.xml from the exception_handling project.


<?xml version="1.0" encoding="UTF-8"?>

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


	<package name="com" extends="struts-default">

			<result name="error">/error.jsp</result>

			<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>

		<action name="login" class="com.candidjava.controller.Login">
			<result name="success">/success.jsp</result>






        Struts 2 global exception war

        Struts 2 global exception maven zip

Related Post