1 / 10

J2EE —— 第 13 章 Java Serer Pages 文档

J2EE —— 第 13 章 Java Serer Pages 文档. JSP 文档的好处. 编辑 验证 名称空间 数据交换 简化了复杂性 提高了灵活度. 标准语法和 XML 语法. 创建 JSP 文档. <%@ taglib uri= " http://java.sun.com/jsp/jstl/core " prefix="c" %> <img src="duke.waving.gif"> <input type="text" name="username" size="25">

dory
Download Presentation

J2EE —— 第 13 章 Java Serer Pages 文档

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. J2EE——第13章JavaSerer Pages文档

  2. JSP文档的好处 • 编辑 • 验证 • 名称空间 • 数据交换 • 简化了复杂性 • 提高了灵活度

  3. 标准语法和XML语法

  4. 创建JSP文档 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <img src="duke.waving.gif"> <input type="text" name="username" size="25"> <c:if test="${fn:length(userNameBean.name) > 0}" > <%@include file="response.jsp" %> <html xmlns:c="http://java.sun.com/jsp/jstl/core"> <img src="duke.waving.gif" /> <input type="text" name="username" size="25" /> <c:if test="${fn:length(userNameBean.name) gt 0}" > <jsp:directive.include="response.jsp" /> • 保存为.jspx

  5. 声明标签库 <books xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:u="urn:jsptld:/WEB-INF/tlds/my.tld“ xmlns:u1="urn:jsptagdir:/WEB-INF/tags/mytaglibs/"> <books> <jsp:useBean xmlns:jsp="http://java.sun.com/JSP/Page" id="bookDB" class="database.BookDB" scope="page"> <jsp:setProperty name="bookDB" property="database" value="${bookDBAO}" /> </jsp:useBean> <c:forEach xmlns:c="http://java.sun.com/jsp/jstl/core" var="book" begin="0" items="${bookDB.books}"> ... </c:forEach> </books>

  6. 在JSP文档中包括指令 <books xmlns:jsp="http://java.sun.com/JSP/Page"> <jsp:directive.page errorPage="errorpage.jsp" /> ... </books> <jsp:root version="2.0" > <books ...> ... </books> <jsp:directive.include file="magazine.jspx" /> </jsp:root>

  7. 创建静态内容 <c:forEach var="counter" begin="1" end="${3}"> <jsp:text>${counter}</jsp:text> </c:forEach> • <jsp:text>保留所有空白字符#x20,#x9,#xD,#xA <c:forEach var="i" begin="1" end="${x}"> <![CDATA[<blockquote>]]> </c:forEach> ... <c:forEach var="i" begin="1" end="${x}"> <![CDATA[</blockquote>]]> </c:forEach>

  8. 创建动态内容 • EL表达式、脚本元素、标准动作、定制标签 • JSP文档中,EL操作符<、>、<=、>=、!=要分别替换为lt、gt、le、ge、ne <jsp:element name="${content.headerName}" xmlns:jsp="http://java.sun.com/JSP/Page"> <jsp:attribute name="lang">${content.lang}</jsp:attribute> <jsp:body>${content.body}</jsp:body> </jsp:element> <h1 lang="fr">Heading in French</h1> <jsp:declaration> declaration goes here </jsp:declaration> <jsp:scriptlet> code fragment goes here </jsp:scriptlet> <jsp:expression> expression goes here </jsp:expression>

  9. 使用jsp:root和jsp:output元素 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" > <books>...</books> <magazines>...</magazines> </jsp:root> <jsp:output doctype-root-element="books" doctype-system="books.dtd" /> <!DOCTYPE books SYSTEM "books.dtd" > • 生成XML声明 <?xml version="1.0" encoding="UTF-8" ?> • <jsp:output omit-xml-declaration=“false" /> • 没有jsp:root

  10. 确定JSP文档到容器 • 在web.xml中将jspproperty-group的is-xml元素设置为true • 使用Java Servlet规范2.4版本的web.xml文件,并为JSP文档提供.jspx扩展名 • 在JSP文档中包含一个jsp:root元素

More Related