Просмотр исходного кода

zheng-cms-job完善错误页面

shuzheng 9 лет назад
Родитель
Сommit
894831eb7b

+ 4 - 0
zheng-cms/zheng-cms-job/src/main/resources/i18n/messages_en_US.properties

@@ -0,0 +1,4 @@
+403=Access forbidden!
+404=Page not found!
+500=Internal server error!
+error=Server error!

+ 4 - 0
zheng-cms/zheng-cms-job/src/main/resources/i18n/messages_zh_CN.properties

@@ -0,0 +1,4 @@
+403=\u6CA1\u6709\u6743\u9650\uFF01
+404=\u9875\u9762\u6CA1\u6709\u627E\u5230\uFF01
+500=\u5185\u90E8\u670D\u52A1\u5668\u9519\u8BEF\uFF01
+error=\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF\uFF01

+ 17 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/jsp/403.jsp

@@ -0,0 +1,17 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title><spring:message code="403"/></title>
+</head>
+<body>
+403
+</body>
+</html>

+ 17 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/jsp/404.jsp

@@ -0,0 +1,17 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title><spring:message code="404"/></title>
+</head>
+<body>
+404
+</body>
+</html>

+ 43 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/jsp/500.jsp

@@ -0,0 +1,43 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title><spring:message code="500"/></title>
+</head>
+<body>
+<center style="margin:50px auto">
+	<p>错误代码:500<%//=request.getAttribute("javax.servlet.error.status_code")%></p>
+	<p>您访问的页面有错误!</p>
+	<p>错误原因:${error.message}</p>
+	<p>错误内容:${error}</p>
+	<p><!--页面将在<span id="stime">5</span>秒后-->跳转到<a href="${pageContext.request.contextPath}/">首页</a>!</p>
+</center>
+<%
+/**
+监控出错人的IP
+String ip = request.getHeader(" x-forwarded-for");
+if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
+	ip = request.getHeader(" Proxy-Client-IP"); // 获取代理ip
+}
+if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
+	ip = request.getHeader(" WL-Proxy-Client-IP"); // 获取代理ip
+}
+if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
+	ip = request.getRemoteAddr(); // 获取真实ip
+}
+//out.println(ip+"<br/><br/>你的地址是:<br/><br/>");
+
+Document doc = Jsoup.connect("http://ip.chinaz.com/?IP="+ip).timeout(9000).get();
+Element e = doc.select("#status").first();
+//out.println(e);
+*/
+%>
+</body>
+</html>

+ 17 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/jsp/error.jsp

@@ -0,0 +1,17 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title><spring:message code="error"/></title>
+</head>
+<body>
+error
+</body>
+</html>

+ 17 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/jsp/index.jsp

@@ -0,0 +1,17 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8"/>
+    <title>首页</title>
+</head>
+<body>
+index
+</body>
+</html>

+ 29 - 0
zheng-cms/zheng-cms-job/src/main/webapp/WEB-INF/web.xml

@@ -51,4 +51,33 @@
         <servlet-name>springMVC</servlet-name>
         <url-pattern>/</url-pattern>
     </servlet-mapping>
+
+    <!-- session配置 -->
+    <session-config>
+        <session-timeout>30</session-timeout>
+    </session-config>
+
+    <!-- 欢迎页面 -->
+    <welcome-file-list>
+        <welcome-file>index.html</welcome-file>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+
+    <!-- 错误页面 -->
+    <error-page>
+        <error-code>403</error-code>
+        <location>/WEB-INF/jsp/403.jsp</location>
+    </error-page>
+    <error-page>
+        <error-code>404</error-code>
+        <location>/WEB-INF/jsp/404.jsp</location>
+    </error-page>
+    <error-page>
+        <error-code>500</error-code>
+        <location>/WEB-INF/jsp/500.jsp</location>
+    </error-page>
+    <error-page>
+        <exception-type>java.lang.Throwable</exception-type>
+        <location>/WEB-INF/jsp/error.jsp</location>
+    </error-page>
 </web-app>