6:22 am - Sunday October 22, 2017

Struts 2 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 Exception Handling Example and Tutorial

Screenshot-4

 

Errorhandling.java

 


package com.candidjava.controller;
import com.opensymphony.xwork2.ActionSupport;
public class ErrorHandling extends ActionSupport{
private static final long serialVersionUID = 1L;

public String execute()
{

throw new NumberFormatException();
}

}

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">
<action name="helloo">
<exception-mapping result="error" exception="java.lang.NumberFormatException"></exception-mapping>
<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 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 Exception Handling program..

Output Screenshots

ScreenshotScreenshot-1

     Download Struts2_validation_properties

BACK

Filed in: Struts 2 Tutorial

Comments are closed.