petclinic-aplcache

Simplified exception page handling - so we don't use JSP scriptlets

1/16/2013 2:46:23 AM

Changes

src/main/webapp/WEB-INF/jsp/dataAccessFailure.jsp 30(+0 -30)

src/main/webapp/WEB-INF/jsp/uncaughtException.jsp 64(+0 -64)

Details

diff --git a/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java b/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java
index 4ffcd71..8d5ea2d 100644
--- a/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java
+++ b/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java
@@ -1,12 +1,20 @@
 
 package org.springframework.samples.petclinic.web;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.propertyeditors.CustomDateEditor;
+import org.springframework.beans.propertyeditors.StringTrimmerEditor;
 import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.PetType;
 import org.springframework.samples.petclinic.Vets;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
diff --git a/src/main/webapp/WEB-INF/jsp/exception.jsp b/src/main/webapp/WEB-INF/jsp/exception.jsp
new file mode 100644
index 0000000..35bfc43
--- /dev/null
+++ b/src/main/webapp/WEB-INF/jsp/exception.jsp
@@ -0,0 +1,21 @@
+<html lang="en">
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
+
+<jsp:include page="header.jsp"/>
+
+<body>
+  	<div class="container">
+		<spring:url value="/resources/images/banner-graphic.png" var="banner"/>
+		<img src="${banner}" />
+		<spring:url value="/resources/images/pets.png" var="petsImage"/>
+		<img src="${petsImage}" />
+		<h2>Something happened...</h2>
+		<p>${exception.message}</p>
+		
+	
+		<jsp:include page="footer.jsp"/>
+
+  	</div>
+</body>
+
+</html>
diff --git a/src/main/webapp/WEB-INF/petclinic-servlet.xml b/src/main/webapp/WEB-INF/petclinic-servlet.xml
index 153fd45..d203e4a 100644
--- a/src/main/webapp/WEB-INF/petclinic-servlet.xml
+++ b/src/main/webapp/WEB-INF/petclinic-servlet.xml
@@ -75,8 +75,6 @@
 	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
 			p:basename="messages/messages"/>
 	
-
-	
 	<!--
 		Processes annotated handler methods, applying PetClinic-specific request parameter binding. 
 	-->
@@ -93,32 +91,10 @@
 		- here with all other types of exceptions.
 	-->
 	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
-		<property name="exceptionMappings">
-			<props>
-				<prop key="org.springframework.web.servlet.PageNotFound">pageNotFound</prop>
-				<prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
-				<prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
-			</props>
-		</property>
-		<property name="defaultErrorView" value="uncaughtException"/>
+		<property name="defaultErrorView" value="exception"/>
 	</bean>
 
-	<!--
-		- This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
-		- and uses the requested media type to pick a matching view. When the media type is 'text/html',
-		- it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
-		- BeanNameViewResolver. Note the use of the expression language to refer to the contentType
-		- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
-	-->
-	
-	
-
-	
-
-	
-
 
-	
 	<!-- 	- The AtomView rendering a Atom feed of the visits  -->
 	 
 	<bean id="visitsList" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
@@ -132,6 +108,4 @@
 		<oxm:class-to-be-bound name="org.springframework.samples.petclinic.Vets"/>
 	</oxm:jaxb2-marshaller>
 
-
-
 </beans>