zoukankan      html  css  js  c++  java
  • Head First Servlet and JSP 笔记 JSP 部分 (未完待续)

    第七章

    1、

    The Container takes what you’ve written in your JSP, translates it into a servlet class source (.java) file, then compiles that into a Java servlet class. 

    2、

     you can put regular old Java code in a JSP using a scriptlet—which just means Java code within a <% ... %> tag. 

    3、

    Use the page directive to import packages 

    To import a single package:

    <%@ page import=”foo.*” %> 

    To import multiple packages:

    <%@ page import=”foo.*,java.util.*” %> 

    4、

    Expression <%= %> 

    NEVER end an expression with a semicolon! 

    5、

    declaration <%! int count=0; %> 

    JSP declarations are for declaring members of the generated servlet class. That means both variables and methods! In other words, anything between the <%! and %> tag is added to the class outside the service method. That means you can declare both static variables and methods. 

    6、隐式对象

    6、

    <!-- HTML comment --> 

    <%-- JSP comment --%> 

    7、

    API for the generated servlet 

    jspInit()
    This method is called from the init() method.

    You can override this method. (Can you figure out how?)

    jspDestroy()

    This method is called from the servlet’s destroy() method. You can override this method as well. 

    8、

    Initializing your JSP 

    Configuring servlet init parameters 

    <web-app ...>
    <servlet>
    <servlet-name>MyTestInit</servlet-name>
    <jsp-file>/TestInit.jsp</jsp-file>
    <init-param>
    <param-name>email</param-name>
    <param-value>ikickedbutt@wickedlysmart.com</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>MyTestInit</servlet-name>
    <url-pattern>/TestInif.jsp</url-pattern>
    </servlet-mapping>
    </web-app>

    Overriding jspInit() 

    <%!
    public void jspInit() {
    ServletConfig sConfig = getServletConfig();;
    String emailAddr = sConfig.getInitParameter(“email”);;
    ServletContext ctx = getServletContext();;
    ctx.setAttribute(“mail”, emailAddr);; }
    %>

    9、attribute in JSP

    10、page attribute

    Using the pageContext to find an attribute when you don’t know the scope <%= pageContext.findAttribute(“foo”) %> 

    (未完待续)

  • 相关阅读:
    element-ui实现表格el-table展开行
    jQuery请求本地JSON文件,在谷歌浏览器运行时报跨域错误
    jQuery使用serialize获取form表单数据,中文乱码问题
    Element-ui局部添加loading效果
    Vue中this.$set的使用
    项目管理【81】 | 项目立项管理
    项目管理【80】 | 知识产权与标准规范-标准规范
    项目管理【79】 | 知识产权与标准规范-政府采购法法
    项目管理【78】 | 知识产权与标准规范-招投标法
    项目管理【77】 | 知识产权与标准规范-合同法
  • 原文地址:https://www.cnblogs.com/wxy325/p/3072328.html
Copyright © 2011-2022 走看看