Por admin | Para la categoría de struts | noticia del 04-08-2009
Cuando se produce un error 404, muchas veces cuando navegamos por internet nos podemos encontrar con este error. La visualización del mismo depende del navegador que estemos utilizando o bien de la gestión de dicho error por parte del sito web al que queremos acceder.
En struts también podemos gestionar dichos errores, para ello nos vamos al fichero de descriptor de despliegue web.xml y escribimos lo siguiente
1 2 3 4 5 6 | <!-- declaramos la página de error --> <error-page> <error-code>404</error-code> <location>/pages/404.jsp</location> </error-page> |
1 2 3 4 | <error-page> <error-code>500</error-code> <location>/pages/500.jsp</location> </error-page> |
Las situaciones en las que se produce este error serian cuando nos brindan un enlace a un sitio y el recurso al que apunta el enlace no existe o bien cuando escribimos directamente una dirección de una página sobre un sitio web y lo hacemos mal.
Para el error 500 claves para MessageResources.properties
1 2 3 4 5 6 7 8 9 10 11 | # error 404 error.404.titulo = Recurso no disponible error.404.imagen = ../imagenes/cancelado.png error.404.imagen.alt = no disponible error.404.mensaje = página no encontrada # error 500 error.500.titulo = Error en la p´gina error.500.imagen = ../imagenes/cancelado.png error.500.imagen.alt = no disponible error.500.mensaje = Lo sentimos, se ha producido un error interno |
Para la página 404.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><bean:message key="error.404.titulo"/></title> <html:base/> </head> <body> <div style="float:left; margin-left:200px"> <h1> <bean:message key="error.404.mensaje"/> </h1> </div> <html:img srcKey="error.404.imagen" titleKey="error.404.imagen.alt"/> </body> </html:html> |
Para la página 500.jsp
Exactamente igual
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><bean:message key="error.500.titulo"/></title> <html:base/> </head> <body> <div style="float:left; margin-left:200px"> <h1> <bean:message key="error.500.mensaje"/> </h1> </div> <html:img srcKey="error.500.imagen" titleKey="error.500.imagen.alt"/> </body> </html:html> |
Error 500 ejemplo

