Unit04: JSP基本语法 、 JSP运行原理

    Unit04: JSP基本语法 、 JSP运行原理    

hello.jsp

<%@page pageEncoding="utf-8"%>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>第一个JSP</title>
    </head>
    <body>
        <!-- 3.JSP声明:声明变量或方法 -->
        <%!
            public double pf(double d) {
                return d*d;
            }
        %>
        <ul>
            <!-- 1.JSP脚本:完整的Java代码段 -->
            <%
                for(int i=0;i<10;i++) {
            %>
                <!-- 2.JSP表达式:要输出的内容 -->
                <li><%=pf(Math.random()) %></li>
            <%        
                }
            %>
        </ul>
        
        <!-- 引入time.jsp,将其内容作为
            当前网页的一部分. -->
        <%@include file="time.jsp"%>
        
    </body>
</html>

time.jsp

<!-- 
pageEncoding:声明此jsp文件的编码.
contentType:声明给浏览器输出的内容的类型.
 -->
<%@page pageEncoding="utf-8"
    contentType="text/html"
    import="java.util.*,java.text.*"%>
<%
    Date date = new Date();
    SimpleDateFormat sdf = 
        new SimpleDateFormat("HH:mm:ss");
    String now = sdf.format(date);
%>
<p><%=now %></p>
原文地址:https://www.cnblogs.com/tangshengwei/p/6427079.html