| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<!-- |
| 3 |
|
| 4 |
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 5 |
|
| 6 |
Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. |
| 7 |
|
| 8 |
The contents of this file are subject to the terms of either the GNU |
| 9 |
General Public License Version 2 only ("GPL") or the Common Development |
| 10 |
and Distribution License("CDDL") (collectively, the "License"). You |
| 11 |
may not use this file except in compliance with the License. You can |
| 12 |
obtain a copy of the License at |
| 13 |
http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 14 |
or packager/legal/LICENSE.txt. See the License for the specific |
| 15 |
language governing permissions and limitations under the License. |
| 16 |
|
| 17 |
When distributing the software, include this License Header Notice in each |
| 18 |
file and include the License file at packager/legal/LICENSE.txt. |
| 19 |
|
| 20 |
GPL Classpath Exception: |
| 21 |
Oracle designates this particular file as subject to the "Classpath" |
| 22 |
exception as provided by Oracle in the GPL Version 2 section of the License |
| 23 |
file that accompanied this code. |
| 24 |
|
| 25 |
Modifications: |
| 26 |
If applicable, add the following below the License Header, with the fields |
| 27 |
enclosed by brackets [] replaced by your own identifying information: |
| 28 |
"Portions Copyright [year] [name of copyright owner]" |
| 29 |
|
| 30 |
Contributor(s): |
| 31 |
If you wish your version of this file to be governed by only the CDDL or |
| 32 |
only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 33 |
elects to include this software in this distribution under the [CDDL or GPL |
| 34 |
Version 2] license." If you don't indicate a single choice of license, a |
| 35 |
recipient has the option to distribute your version of this file under |
| 36 |
either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 37 |
its licensees as provided above. However, if you add GPL Version 2 code |
| 38 |
and therefore, elected the GPL Version 2 license, then the option applies |
| 39 |
only if the new code is made subject to such option by the copyright |
| 40 |
holder. |
| 41 |
|
| 42 |
--> |
| 43 |
<html> |
| 44 |
<head> |
| 45 |
<title>Freemaker example</title> |
| 46 |
<style type="text/css"><!-- |
| 47 |
.figure { text-align:center; |
| 48 |
margin: 20px} |
| 49 |
.cliSample { background-color:lightgray } |
| 50 |
--></style> |
| 51 |
</head> |
| 52 |
|
| 53 |
|
| 54 |
<body> |
| 55 |
<h1>Freemaker example</h1> |
| 56 |
<p>This example demonstrates how to use Freemarker templating engine to produce web pages via Jersey viewable support. |
| 57 |
Both explicit and implicit viewable patterns are demonstrated using the FreemarkerResource resource class.</p> |
| 58 |
|
| 59 |
<h2>Content</h2> |
| 60 |
<p>See FreemarkerResource for details on how to use jersey-freemaker module for generating web pages. |
| 61 |
The explicit viewable generating sub-resource method in the FreemarkerResource class is quite self-descriptive. |
| 62 |
Since Jersey implicit viewables feature is turned on in the Main class, an implicit viewable generating resource method |
| 63 |
will be automatically generated by Jersey runtime for the FreemarkerResource class and mapped to GET requests in addition.</p> |
| 64 |
|
| 65 |
<p>Notice: If you want to use freemarker in your project, don't forget to set <b>"com.sun.jersey.freemarker.templateBasePath"</b> init param, which |
| 66 |
will be pointing to the base directory where your templates are stored (The application Main class as well as |
| 67 |
the FreemarkerTest class does exactly that to make the <code>hello.ftl</code> template available for Jersey runtime).</p> |
| 68 |
|
| 69 |
<h2>Running the Example</h2> |
| 70 |
<p>Run the example as follows:</p> |
| 71 |
<blockquote><pre> |
| 72 |
mvn clean compile exec:java</pre></blockquote> |
| 73 |
<p>This deploys this example using |
| 74 |
<a href="http://grizzly.java.net/">Grizzly</a> |
| 75 |
</p> |
| 76 |
<p>You can then check the output produced by Freemarker at the following URIs: |
| 77 |
<ul> |
| 78 |
<li><a href="http://localhost:9998/">http://localhost:9998/</a> - implicit, Jersey generated, view</li> |
| 79 |
<li><a href="http://localhost:9998/explicit">http://localhost:9998/explicit</a> - explicit, application created, view</li> |
| 80 |
</ul> |
| 81 |
</p> |
| 82 |
</html> |