Hi Thierry,
Thanks for your reply, i tried to get the files from classpath
using CLAP.i have "template" directory in the classpath. but it is still not
able to read the files in that folder.actually i am trying to use freemarker
template files stored in my classpath to render output.
code is ...
public Representation getRepresentation(Variant variant) {
Representation result = null;
if (variant.getMediaType().equals(MediaType.TEXT_HTML)) {
try {
// page.buildFromBackend(getRequest());
result = new
TemplateRepresentation(getTemplateName(),
configme(), getItem(),
MediaType.TEXT_HTML);
}
---
}
return result;
}
Configuration configme() throws IOException{
Configuration config=null;
config=new Configuration();
File templateDir=new File("clap:///template");
TemplateLoader fileTemplateLoader=new
FileTemplateLoader(templateDir);
config.setTemplateLoader(fileTemplateLoader);
return config;
}
String getTemplateName() { return "oneitem.ftl"; }
Stack Trace :
java.io.FileNotFoundException: clap:\template does not exist.
at
freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:125)
at java.security.AccessController.doPrivileged(Native Method)
at
freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:122)
---
---
please help me .. Thanks
Thierry Boileau wrote:
>
>
> Hello,
>
>
> you can use the WAR protocol scheme (used for serving files from a war
> application deployed inside a servlet container), or the CLAP one
> (looks for "files" from the classpath).
> For example, if your "items" directory is located just under the
> "Web-Content" directory:
>
> FileRepresentation rep=new
> FileRepresentation("war:///items/result.jsp",MediaType.TEXT_HTML);
>
> I would like to precise the FileRepresentation simply gets the content
> of the targetted file.
>
>
> Best regards,
> Thierry Boileau
> --
> Restlet
> ~ Core developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>
>
> I am trying to create a web application with restlet. how can i call
> a
> file in the web application (using relative path).
> I went through documentation of restlet, there creating html content in
> the
> Resource class was explained as shown here.
>
> getResponse().setStatus(Status.SUCCESS_CREATED);
> String result="<h3>Item Created. </h3>";
> result += " <p>use <br>
> http://localhost:8080/itemRestlet/itemapp/items <br>in
> a new browser instance to see the data.</p>";
> Representation rep = new StringRepresentation(result,MediaType.TEXT_HTML);
>
> The FileRepresentation class can take path of the file you want to
> invoke and content type, but here the problem is trying to locate
> result.jsp
> in the webserver installation directory rather than in webapp.
>
> FileRepresentation rep=new
> FileRepresentation("items/result.jsp",MediaType.TEXT_HTML);
>
> Can any one please help me to invoke this result.jsp from a
> resource?
> I am trying to invoke a html/jsp page from web application from a
> resource....help me please
>
>
>
>
>
>
--
View this message in context:
http://n2.nabble.com/refering-a-web-app-file-with-FileRepresentation-tp1493159p1509435.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.