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