Java for Web学习笔记(十六):JSP(6)jspx

JSP document的后缀名是.jspx,它采用XML格式,因此表述方式完全不同:

 

JSP语法

JSP document语法

Page Directive

<%@ page %>

<jsp:directive.page />

Include Directive

<%@ include %>

<jsp:directive.include />

Tag Library Directive

<%@ taglib %>

xmlns:prefix=”Library URI”

Declartion

<%! … %>

<jsp:declaration> … </jsp:declaration>

Scriplet

<% … %>

<jsp:scriptlet> … </jsp:scriptlet>

Expression

<%= … %>

<jsp:expression> … </jsp:expression>

Comment

<%-- … --%>

<!--  …  -->

下面是一个简单JSP document的例子,最基本的差异就是书写的格式不同。

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns="http://www.w3.org/1999/xhtml" version="2.0"
    xmlns:jsp=http://java.sun.com/JSP/Page xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:directive.page contentType="text/html;charset=UTF-8" language="java" />
<jsp:directive.include file="/WEB-INF/jsp/base.jspx" />
<jsp:declaration>
    private static final String DEFAULT_USER = "Guest";
</jsp:declaration>
<jsp:scriptlet>
    String user = request.getParameter("user");
    if(user == null)
        user = DEFAULT_USER;
</jsp:scriptlet>
<!-- <jsp:expression>"This code is commented"</jsp:expression> -->
<!DOCTYPE html>
<html>
<head>
    <title>Hello User Application</title>
</head>
<body>
    Hello, <jsp:expression>user</jsp:expression>!<br /><br />
    <form action="greeting.jsp" method="post">
        Enter your name:<br />
        <input type="text" name="user" /><br />
        <input type="submit" value="Submit" />
    </form>
</body>
</html>
</jsp:root>

相关链接: 我的Professional Java for Web Applications相关文章

你可能感兴趣的:(Java for Web学习笔记(十六):JSP(6)jspx)