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

本文介绍了JSPdocument的.jspx后缀及其XML格式,并通过表格形式详细对比了传统JSP语法与JSPdocument语法的区别,包括PageDirective、IncludeDirective等。同时提供了一个简单的JSPdocument示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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相关文章

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值