| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 1 | <?xml version="1.0"?>
 | 
 | 2 | <!--
 | 
 | 3 |  Licensed to the Apache Software Foundation (ASF) under one or more
 | 
 | 4 |   contributor license agreements.  See the NOTICE file distributed with
 | 
 | 5 |   this work for additional information regarding copyright ownership.
 | 
 | 6 |   The ASF licenses this file to You under the Apache License, Version 2.0
 | 
 | 7 |   (the "License"); you may not use this file except in compliance with
 | 
 | 8 |   the License.  You may obtain a copy of the License at
 | 
 | 9 | 
 | 
 | 10 |       http://www.apache.org/licenses/LICENSE-2.0
 | 
 | 11 | 
 | 
 | 12 |   Unless required by applicable law or agreed to in writing, software
 | 
 | 13 |   distributed under the License is distributed on an "AS IS" BASIS,
 | 
 | 14 |   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
 | 15 |   See the License for the specific language governing permissions and
 | 
 | 16 |   limitations under the License.
 | 
 | 17 | -->
 | 
 | 18 | <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
 | 
 | 19 |   version="1.2">
 | 
 | 20 | <jsp:directive.page contentType="text/html"/>
 | 
 | 21 | <jsp:directive.page import="java.util.Date, java.util.Locale"/>
 | 
 | 22 | <jsp:directive.page import="java.text.*"/>
 | 
 | 23 | 
 | 
 | 24 | <jsp:declaration>
 | 
 | 25 |   String getDateTimeStr(Locale l) {
 | 
 | 26 |     DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l);
 | 
 | 27 |     return df.format(new Date());
 | 
 | 28 |   }
 | 
 | 29 | </jsp:declaration>
 | 
 | 30 | 
 | 
 | 31 | <html>
 | 
 | 32 | <head>
 | 
 | 33 |   <title>Example JSP in XML format</title>
 | 
 | 34 | </head>
 | 
 | 35 | 
 | 
 | 36 | <body>
 | 
 | 37 | This is the output of a simple JSP using XML format. 
 | 
 | 38 | <br />
 | 
 | 39 | 
 | 
 | 40 | <div>Use a jsp:scriptlet to loop from 1 to 10: </div>
 | 
 | 41 | <jsp:scriptlet>
 | 
 | 42 | // Note we need to declare CDATA because we don't escape the less than symbol
 | 
 | 43 | <![CDATA[
 | 
 | 44 |   for (int i = 1; i<=10; i++) {
 | 
 | 45 |     out.println(i);
 | 
 | 46 |     if (i < 10) {
 | 
 | 47 |       out.println(", ");
 | 
 | 48 |     }
 | 
 | 49 |   }
 | 
 | 50 | ]]>
 | 
 | 51 | </jsp:scriptlet>
 | 
 | 52 | 
 | 
 | 53 | <!-- Because I omit br's end tag, declare it as CDATA -->
 | 
 | 54 | <![CDATA[
 | 
 | 55 |   <br><br>
 | 
 | 56 | ]]>
 | 
 | 57 | 
 | 
 | 58 | <div align="left">
 | 
 | 59 |   Use a jsp:expression to write the date and time in the browser's locale: 
 | 
 | 60 |   <jsp:expression>getDateTimeStr(request.getLocale())</jsp:expression>
 | 
 | 61 | </div>
 | 
 | 62 | 
 | 
 | 63 | 
 | 
 | 64 | <jsp:text>
 | 
 | 65 |   <p>This sentence is enclosed in a jsp:text element.</p>
 | 
 | 66 | </jsp:text>
 | 
 | 67 | 
 | 
 | 68 | </body>
 | 
 | 69 | </html>
 | 
 | 70 | </jsp:root>
 |