jsp内置对象之page,pageContext,config,exception
2016-09-23 20:12
871 查看
jsp内置对象之page,pageContext,config,exception
page:代码:
当前page页面对象的字符串描述:<%=page.toString() %>
结果:
page内置对象
当前page页面对象的字符串描述:org.apache.jsp.page_jsp@1dc66fdpageContext:
代码:
pageContext.jsp:
<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8"%>
<%
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 'out.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>
<h1>pageContext内置对象</h1>
<hr>
用户名是:<%=pageContext.getSession().getAttribute("username") %>
<%
//跳转到注册页面
//pageContext.forward("reg.jsp");
pageContext.include("include.jsp");
%>
</body>
</html>
include.jsp:
<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
String s=sdf.format(date);
out.println(s+"<br>");
%>
结果:
pageContext内置对象
用户名是:admin 2016年09月23日config:
exception:
程序:
exception.jsp:
<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8" errorPage="exception_text.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 'out.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>
<!--
如需使用异常处理
在第一行添加:errorPage="exception_text.jsp"
-->
<body>
<h1>测试异常的界面</h1>
<hr>
<%
System.out.println(100/0);//抛出运行异常,算术异常
%>
</body>
</html>
exception_text.jsp:
<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8" errorPage="exception.jsp" 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 'out.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>
<!--
如需使用异常处理
在第一行添加:isErrorPage="true"
-->
<body>
<h1>exception内置对象</h1>
<hr>
异常消息:<%=exception.getMessage() %><br>
异常的字符串描述:<%=exception.toString() %>
</body>
</html>
结果:
exception内置对象
异常消息:/ by zero异常的字符串描述:java.lang.ArithmeticException: / by zero
相关文章推荐
- jsp九大内置对象:request、response、session、application、out、page、pageContext、config、exception
- JSP内置对象——application,page,pageContext,config,Exception
- JSP内置对象详解4 之 page、out、exception、config、pageContext 内置对象
- jsp内置对象page对象、pageContext对象、Config对象、exception对象
- jsp内置对象out、request、response、session、application五大常用对象以及Page、pageContext、exception、config
- JSP的内置对象(三)appliaction、page、pageContext、config、Exception
- JSP内置对象详解4 之 page、out、exception、config、pageContext 内置对象
- JSP内置对象之application、out、pageContext、config、page、exception
- JSP内置对象:request, reponse, out, session, application, config, pagecontext, page, exception
- JSP内置对象--pageContent,request,response,session,application,config,out,page,exception
- jsp九大内置对象(三)page、config、exception
- jsp request、response、session、out、page、application、exception、pageContext、config对象详解
- JSP九大内置对象---Request,Response,Out,Session,Application,Cookie,Config,Page,Exception
- jsp内置对象application、exception、pageContext、config方法
- JSP内置对象application、out、page、config,exception总结(五)
- JSP内置对象之session application page pageContext config exception
- JSP九大内置对象(Request,Response,Out,Session,Application,Cookie,Config,Page,Exception)
- JSP内置对象---application 对象,page对象,pageContext对象
- 浪潮优派培训笔记:JSP的9大内置对象之(一).与Servlet有关的内置对象: page、config
- jsp九大内置对象 page与pageContext的区别