【每天学一点】JSP相关

来源:互联网 发布:支持xen的linux内核 编辑:程序博客网 时间:2024/06/07 15:40

  依旧无聊热啊!
  


<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"    session="true"    %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>helloworld</title></head><body>hello world ,it is a welcome page.<%/*** * JSP 9大内置对象 * 内置对象名                类型 * request          HttpServletRequest * response         HttpServletResponse * config           ServletConfig * application      ServletContext * session          HttpSession * exception        Throwable * out              JspWriter * page             Object(this) * pageContext      PageContext *  * @author reimu * *///1.Out 对象 相当于带缓存的PrintWriter        //JspWriter缓存区往外写出:1。缓存区满了 2.刷新缓存区 out.flush();3.关闭缓存区 out.clearBuffer();4.执行完JSP页面(大小8KB)    out.write(session.getId());  //最后输出    response.getWriter().write("abc");  //第一个输出    //1.1手动刷新缓存    out.write("aaa");    //out.flush();//刷新    //out.clear();    response.getWriter().write("bbb");//2.pageContext对象 是jsp的上下文对象 用于共享Jsp数据。只能在本页面使用    //2.1保存在page域中    pageContext.setAttribute("name", "reimu"); //同页面使用    //2.2保存在request,session,context域中    pageContext.setAttribute("age", "12", PageContext.REQUEST_SCOPE); //转发可以获取   ,同请求使用    pageContext.setAttribute("age", "13", PageContext.SESSION_SCOPE);  //不关闭浏览器,session可以在别的页面取到  ,同会话使用    pageContext.setAttribute("age", "14", PageContext.APPLICATION_SCOPE);  //服务器不关闭,也可以在别的页面取到  ,同web应用    String name=(String)pageContext.getAttribute("name");%><%=name %><br/><%=session.getAttribute("age") %><br/><%=request.getAttribute("age") %><br/><%=pageContext.getAttribute("age", PageContext.APPLICATION_SCOPE) %><%//findAttribute():自动搜索    //顺序page-request-session-context%><%=pageContext.findAttribute("age") %><%//转发//request.getRequestDispatcher("test2.jsp").forward(request, response);%></body></html>
0 0