jsp内置对象之page,pageContext,config,exception

jsp内置对象之page,pageContext,config,exception

  page:


代码: 

当前page页面对象的字符串描述:<%=page.toString() %>

结果:

page内置对象


当前page页面对象的字符串描述:org.apache.jsp.page_jsp@1dc66fd           


pageContext:





代码:

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           

















  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值