JSPÒ³ÃæµÄ´íÎó´¦Àí
Æä´úÂëÈçÏÂ:
<%@page language="java" contentType="text/html" import="java.util.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<%
int a=9;
int b=0;
try{
%>
<%=(a/b)%>
<%
}catch(Exception e){
out.println("page error");//Êä³öµ½µ±Ç°Ò³Ãæ
out.println("<br>");
out.println(e.getMessage());
System.out.print(e.getMessage());//Êä³öµ½¿ØÖÆ̨
}
%>
<c:catch var="error_Message"> //½øÐгý0µÄ´íÎó²¶×½
<h1><%=3/0 %>3/0</h1>
</c:catch>
<c:out value="${error_Message}" />//½«²¶×½µ½µÄ´íÎóÐÅÏ¢Êä³öµ½µ±Ç°Ò³Ãæ
</body>
</html>
ÔËÐнá¹ûÈçÏÂ:
page error
/ by zero
java.lang.ArithmeticException: / by zero
ÁíÍâJSP»¹ÓÐÒ»ÖÖ´íÎóÒ³ÃæµÄÌøת,ÈçÏÂ:
<%@page language="java" contentType="text/html" import="java.util.*" errorPage="error.jsp" %>
¼ÓÁËÒ»¾äerrorPage="error.jsp".
error.jsp´úÂëÈçÏÂ:
<%@page language="java" contentType="text/html" isErrorPage="true" %>
<html>
<body>
<h1><%=exception.getMessage()%></h1>
</body>
</html>
´ËÒ³ÃæµÄÖصãÊÇÔÚµÚÒ»¾äÖмÓÈëisErrorPage="true" ¾ä,ĬÈÏÇé¿öÏÂΪfalse.
µ±Ê±²âÊÔʱÈçÏ´úÂë:
<%=3/0%>,ÆäËüµÄʲô¶¼²»ÓÃд,Èç¹ûÔÚµ±Ç°Ò³ÒÑÖ¸¶¨ÁËerrorPage="error.jsp"ÏîÔò»á½øÐÐÌøת,Ä¿±êΪerror.jspÒ³.ÎÒÔÚ²âÊÔʱµÚÒ»´ÎÖ´ÐÐJSPÒ³ÃæʱÊDZ༲»¹ýÈ¥ÁË,±¨"http 500 ÄÚ²¿·þÎñÆ÷´íÎó",Èç¹û½«ÆäÖеÄ0¸Ä³É·Ç0ÊýÔò¿Éͨ¹ý,ÔÚÖ´ÐÐÆÚ¼äÔٸĻØ0ÊÇ¿ÉÒÔÕý³£Ö´ÐеÄ,ÔÚÎÒÏëÀ´ÊÇjsp±à¼µÄÎÊÌâ°É,Ò²²»Ô¸ÒâÔÙÉîÈëÑо¿ÁË,Èç¹ûËÓа취½â¾ö,¿ÉÒÔ¸æËßÎÒ,ÏÈÐиÐлÁË!~~
»¹ÓÐÔÚweb.xmlÖеĴ¦Àí·½·¨,ÅäÖÃerror-pageÏî,ÈçÏÂÁ½Àý:
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
ÕâÊÇÅäÖ÷¢Éú500´íÎó(¼´·þÎñÆ÷ÄÚ²¿´íÎó£©Ê±£¬Ìøתµ½´íÎó´¦ÀíÒ³Ãæerror.jsp.
Ïà¹ØÎĵµ£º
Web.xml³£ÓÃÔªËØ
<web-app>
<display-name></display-name>¶¨ÒåÁËWEBÓ¦ÓõÄÃû×Ö
<description></description> ÉùÃ÷WEBÓ¦ÓõÄÃèÊöÐÅÏ¢
<context-param></context-param> context-paramÔªËØÉùÃ÷Ó¦Ó÷¶Î§Äڵijõʼ»¯²ÎÊý¡£
<filter></filter> ¹ýÂËÆ÷ÔªËؽ«Ò»¸ ......
member.jsp //sessionÏÞÖÆ·ÃÎÊÒ³
<%
String url = ""
if(session.getAttribute("username")==null)
{
url = myRedirect.dealurl(request);//¼Ç¼µ±Ç°µØÖ·ºÍÇëÇó²ÎÊý£¬dealurl½«Êµ¼Êurl´¦ÀíÁ˱ÜÃâºÍÒªÇëÇóurlÓиÉÈÅ,ÒòΪ»áÓÐ& ×Ö·û
......
this.state="01";ͨ³£µÄ×ö·¨ÊÇдһ¸öÀࣨ½Ó¿Ú£©À´´æ·Å³£Á¿
public interface MyConstant
{
public static final String STATE_01= "01";
}
È»ºóÔÚ³ÌÐòÖÐÕâÑùд¾Í¿ÉÒÔÁË
this.state=MyConstant.STATE_01;
ÔÚJava³ÌÐòÖÐÕâÑù¾Í¿ÉÒÔ±ÜÃâÓ²±àÂëÁË¡£¿ÉÊÇJSPÖÐÄØ£¿µ±È»£¬Èç¹ûJSPÖÐÔÊÐíʹÓÃScripletµÄ»°µ±È»Ò²¿ÉÒÔÖ±½ÓʹÓó ......
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%
String[] cookiename = {"JSESSIONID","SECURE_AUTH_ROOT_COOKIE","SECURITY_AUTHENTICATION_COOKIE"};
for(int index = 0, len = cookiename.length; index < len; index ++) {
javax.servlet.http.Cookie c = new javax.s ......