3:13 pm - Monday December 16, 9574

Struts 2 Global Exception Handling Example and Tutorial

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Struts 2 Global Exception Handling Example and Tutorial

Screenshot-2

GobalErrorHandling.java


package com.candidjava.controller;

import com.opensymphony.xwork2.ActionSupport;

public class GlobalErrorHandling extends ActionSupport {
private static final long serialVersionUID = 1L;

public String execute() {

throw new IllegalArgumentException();
}

}

struts.xml


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

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

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

<global-exception-mappings>
<exception-mapping result="error"
exception="java.lang.IllegalArgumentException"></exception-mapping>
</global-exception-mappings>

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

</action>

</package>
</struts>

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

index.jsp


<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
<body>

<s:form action="helloo">
<h4>
<u>Struts2 Global Exception Handling Example</u>
</h4>

<s:submit value="Click"></s:submit>

</s:form>
</body>
</html>

error.jsp


<%@ taglib prefix="s" uri="/struts-tags" %>

Welcome ,
You have been successfully executed struts 2 Global Exception Handling program..

Output Screenshots

ScreenshotScreenshot-1

  Download Struts2_GlobalException Handling

BACK

 

Filed in: Struts 2 Tutorial

Comments are closed.