jsp三大指令
一个jsp页面中可以有0-N个指令
1.page--->最复杂:<%@page language="" ...%>
*pageEncoding和contentType
pageEncoding:指定当前jsp页面的编码,只要不说谎,就不会有乱码!在服务器要把jsp编译成.java时需要使用pageEncoding
contentType:它表示添加一个响应头:Content-Type ,相当于response.setContentType()
*import:导包,可以出现多次
*errorPage和isErrorPage
errorPage:当前页面如果抛出异常,那么要转发到哪一个页面,由errorPage决定,状态码为200
isErrorPage:指定页面为处理错误页面!当该属性为true时,这个页面会设置状态码为500,而且这个页面可以使用9大内置对象中的exception
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" errorPage="error/error.jsp"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'a.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% int a=13/0; %> </body> </html> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isErrorPage="true"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'error.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 哈哈,出错了!<br/> <% //<%=exception.getMessage()% > <br/> //<%exception.printStackTrace(response.getWriter()); % > //当然,一般不会直接将错误信息显示给用户,会变得人性化 %> </body> </html>