JSP学习笔记(三) JSP内建对象 web应用欢迎文件 MVC思想

1 内建对象
JSP中的隐含对象:不用我们手工去创建的对象
// JspWriter out                  -- to write to the browser
// HttpServletRequest  request    -- the request object.
// HttpServletResponse response   -- the response object.
// PageContext pageContext        -- the page context for this JSP
// HttpSession session            -- the session object for the client (if any)
// ServletContext application     -- The servlet (application) context
// ServletConfig config           -- The ServletConfig for this JSP
// Object page                    -- the instance of this page's implementation class (i.e., 'this')

// exception   <%@page isErrorPage="true"%>


四个范围对象:pageContext,request,session,application
<jsp:useBean id="stu" class="vo.Student" scope="session"/>
等价的代码
<%
Student stu=pageContext.getAttribute("stu");
if(stu==null) stu=new Student();
pageContext.setAttribute("stu",stu);
%>

//page,reqeust,session,application

<%
  pageContext.setAttribute("name", "maxwell");
  pageContext.setAttribute("sex", "m");
  pageContext.setAttribute("age", "28");
 
  request.setAttribute("name", "maxwell");
  request.setAttribute("sex", "m");
  request.setAttribute("age", "28");
 
  session.setAttribute("name", "maxwell");
  session.setAttribute("sex", "m");
    session.setAttribute("age", "28");
   
  application.setAttribute("name", "maxwell");
  application.setAttribute("sex", "m");
  application.setAttribute("age", "28");
%>

next.jsp
out:
<%out.println("Hello JSP!");%>
<%System.out.println("Hello JSP!");%>
getBufferSize()             :tomcat default:8k
getRemaining()
flush()
clearBuffer()

request:
getProtocol()
getMethod()
getHeader("User-Agent")
getCookies()
getRequestURI()
getRequestURL()
getContextPath()
getServletPath()
getQueryString()
isRequestedSessionIdFromCookie()
isRequestedSessionIdFromURL()
request.isRequestedSessionIdValid()
getAttribute("name")
getPort(),getRequestDispatcher(),setCharacterEncoding(),getInputStream()

session:
getId()
isNew()
getAttribute("name")
invalidate()
setMaxInactiveInterval(10)

response:
sendRedirect("third.jsp")

application:
log("some body visit our website...");
getAttribute("name")
getMajorVersion()
getMinorVersion()
getServerInfo()
getRequestDispatcher(),getResourceAsStream(),getInitParameter()

pageContext:
getAttribute("name")

config:
getInitParameter("classNo")
getServletName()

page:
getClass()


requestURI = contextPath + servletPath + pathInfo
a getContextPath
b getServletPath
c getPathInfo


2 欢迎文件
缺省情况下,一个Web App中的index.html,index.htm,index.jsp可作为默认的欢迎
文件.当用户请求没有指明要访问的资源时,Web Container会用欢迎文件响应客户端
请求.
手工设置欢迎文件
web.xml
  <welcome-file-list>
    <welcome-file>/a.jsp</welcome-file>
    <welcome-file>/b.jsp</welcome-file>
    <welcome-file>/c.jsp</welcome-file>
  </welcome-file-list>


3 MVC
优化Web App的结构,使用MVC模式
Model 1: JSP + JavaBean(EJB)
Model 2: Servlet + JSP + JavaBean(EJB)------>MVC

MVC: Model-View-Controller

你可能感兴趣的:(tomcat,jsp,mvc,Web,ejb)