JavaWeb_JSP 页面的9个隐含对象

public void_jspServelt(HttpServletRequest request ,HttpServletResponse response)

throws java.io.IOException ,ServletException {

PageContext pageContext = null;

HttpSession session = null;

ServletContext application = null;

JspWriter out = null;

Object page  = this;





}

用<%%>编写的代码在此位置,可以用到request,response,pageContext, Session application

confg out page 这8个隐含对象 实际上还可以使用exception 的隐含对象)

 

1、request  HttpServletRequest的一个对象

2、response: HttpResponse 的一个对象

3、pageContext:页面上下文的对象<自定义标签>,可以从该对象中获取到其他8个隐含对象也可以获取当前页面的其他信息

getPage()  getRequest() getResponse()  getServletConfig() getServletContext() getSession()

4、Session: 浏览器和服务器的一次会话,是HttpSessiond的一个对象

5、application :当前web应用能获取当前应用的初始化参数,是ServletContext的对象

6、config:是当前JSP 的对应的Servlet的 ServletConfig的对象 获取初始化参数

 System.out.println(config.getInitParameter("test"));

 

	<servlet>
		<servlet-name>hellojsp</servlet-name>
		<jsp-file>/hello.jsp</jsp-file>
		<init-param>
			<param-name>test</param-name>
			<param-value>这是个file</param-value>
		</init-param>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>hellojsp</servlet-name>
		<url-pattern>/hellojsp</url-pattern>
	</servlet-mapping>

http://localhost:8181/WebProject_day01/hellojsp 映射路径必须 hellojsp 

7、out : JspWriter对象 调用out.println()可以直接把字符串打印到浏览器上

8、page 指向当前JSP对应的Servlet对象的引用,但为Object类型,只能调用Object类型的方法

9.exception : 在特殊的情况下可用<%@ page isErrorPage="true" %> 在声明了之后才能使用

对属性的作用域的范围从小到大:

pageContext (页面上下文), request (请求),session(浏览器和服务器的一次会话), application(整个WEB应用)

out response config page

exception 

 

和属性相关的方法:

1)方法

Object getAttribute(String name) :获取指定的属性

Enumeration getAttributerNames():获取所有的属性的名字组成的Enumeration对象

removeAttribute(String name): 移除指定的属性

Void  setAttribute(String name ,Object object):设置属性

2).pageContext ,request,session ,Application 都有这些方法

<%
        pageContext.setAttribute("pageContextAttr","pageContextValue");
        request.setAttribute("requestAttr", "requestValue");
        session.setAttribute("sessionAttr", "sessionValue");
        application.setAttribute("applicationAttr","applicationValue");
    %>
    
    
    Page 1 
    <br><br>
    pageContextAttr:<%=pageContext.getAttribute("pageContextAttr") %>    :属性的作用范围仅限于当前JSP页面
    <br><br>
    requestAttr:<%=request.getAttribute("requestAttr") %> : 属性作用范围仅限于同一个请求
    <br><br>
    sessionAttr:<%=session.getAttribute("sessionAttr") %> : 属性范围仅限于一次会话(

    再打开另外一个浏览器,即浏览器打开关闭是一次会话)
    <br><br>
    application:<%=application.getAttribute("applicationAttr") %> :属性范围限于当前WEB应用 全局
    

Page 2

    <br><br>
    pageContextAttr:<%=pageContext.getAttribute("pageContextAttr") %>  null
    <br><br>
    requestAttr:<%=request.getAttribute("requestAttr") %>           null
    <br><br>
    sessionAttr:<%=session.getAttribute("sessionAttr") %>   ----有值 但是关闭浏览器再打开 为null
    <br><br>
    application:<%=application.getAttribute("applicationAttr") %>

 

 

JSP语法

    jsp的表达式<%= %>

JSP声明 :将Java代码封装在<% %>

JSP注释:<% --  %> 

HTML注释:<!-- --> 

jsp注释可以阻止java代码的执行

 

JSP 是Servlet编写的一种技术,它将Java代码和HTML语句混合在同一个文件中编写,

只对网页中的动态产生的内容采用Java代码来编写,而对固定不变的静态内容采用普通静态HTML页面的方式编写

Java Servlet Page :java 服务端网页页面中编写Java代码的页面

JSP可以放置在WEB 应用程序中的除了WEB-INF及其子目录外的其他任何目录中

JSP 页 访问路径和普通HTML页面访问形式也完全一样

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值