Freemarker:-
FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to auto generated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.FreeMarker is designed to be practical for the generation of HTML Web pages, particularly by servlet-based applications following the MVC (Model View Controller) pattern. The idea behind using the MVC pattern for dynamic Web pages is that you separate the designers (HTML authors) from the programmers. Everybody works on what they are good at. Designers can change the appearance of a page without programmers having to change or recompile code, because the application logic (Java programs) and page design (FreeMarker templates) are separated. Templates do not become polluted with complex program fragments. This separation is useful even for projects where the programmer and the HTML page author is the same person, since it helps to keep the application clear and easily maintainable.
Although FreeMarker has some programming capabilities, it is not a full-blown programming language like PHP. Instead, Java programs prepare the data to be displayed (like issue SQL queries), and FreeMarker just generates textual pages that display the prepared data using templates
FreeMarker is not a Web application framework. It is suitable as a component in a Web application framework, but the FreeMarker engine itself knows nothing about HTTP or servlets. It simply generates text. As such, it is perfectly usable in non-web application environments as well. Note, however, that we provide out-of-the-box solutions for using FreeMarker as the view component of Model 2 frameworks (e.g. Struts), which also let you use JSP taglibs in the templates.
/**
* Sample code for generate freemarker template
*/
import java.io.File;
import java.io.StringWriter;
import freemarker.template.Template;
import freemarker.template.Configuration;
import org.apache.commons.io.FileUtils;
import com.custombeans.TemplateBean;
import com.helper.GenerateFileHelper;
class freemarkerDemo{
public static synchronized void generateTemplate() {
try {
Configuration config = new freemarker.template.Configuration().setServletContextForTemplateLoading(servletContext, "/WEB-INF/templates/");
Template tmpl =config.getTemplate("template.ftl");
StringWriter sw = new StringWriter();
Map bean = new HashMap();
bean.put("id",1);
bean.put("FirstName","Amin");
bean.put("LastName","Miral");
tmpl.process(bean, sw);
File resultFile = new File(CONTEXT.getRealPath("template.html"));
try {
FileUtils.writeStringToFile(resultFile, sw.getBuffer().toString(), "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
EDITOR / IDE - Freemarker
Eclipse 3.x Syntax highlight, syntax error indicator, outline view, code completion for macro names and bean property names.
IntelliJ IDEA 8.0 | A well-known feature-rich commercial Java IDE. |
jEdit 4.1 | jEdit is a Free programmer's text editor written in Java. It is highly customizable, extensible, and has an easy-to-use interface. |
SitePad Pro 6 | SitePad Pro is an Integrated Development Environment (IDE) for Java, HTML, VRML and other files. It's commercial software. |
4 comments:
hi all,
I am final year student and doing my final sem project in struts 2.0 framework .. which ide can we use to make a web application under this framework . .
and which web-application server will be easier to configure and easy to work with it. .
----
Presently i am using tomcat . .. and learning the basics using edit plus . .. .but as the no of pages are increasing life is becoming difficult. . even eclipse is not supporting help when i work with jsp pages. . .
thanks and regards,
Praveen
Hi,
You can use Eclipse / MyEclipse / RAD (Rational Application Developer) / AST (Application Server Tool kit) IDE's.
Tomcat is a Servlet container, It may not support for any Transactions. So taht better u can use JBOSS / WebSphere APPLICATION SERVER
Thanks
Elangovan ARUMUGAM
Hi, this example shows how to load from the servlet context. I have my templates in my jar, how do I load templates from the classpath?
Thanks!
STC Technologies knows that students have time and travel constraints and STC Technologies offers a unique solution for your learning requirements.
STC Technologies
Post a Comment