- 浏览: 264343 次
- 性别:
- 来自: 苏州
-
文章分类
- 全部博客 (289)
- java (72)
- oracle (3)
- mysql (5)
- spring (28)
- hibernate (2)
- osgi (0)
- linux (2)
- ExtJs (1)
- jvm (0)
- mybatis (7)
- 分布式 (11)
- MINA (6)
- apache+tomcat (13)
- js+htm (7)
- android (44)
- http (1)
- hbase+hdoop (0)
- memcache (13)
- search (27)
- 部署及性能 (12)
- mongoDB (2)
- 多线程 (12)
- 安全管理验证 (9)
- struts (1)
- webservice (0)
- easyUI (1)
- spring security (16)
- pattern (6)
- 算法 (2)
最新评论
-
lzh8189146:
CommonsHttpSolrServer这个类,现在是不是没 ...
CommonsHttpSolrServer -
xiaochanzi:
我按照你的方法试了下,tomcat6可以发布,但是访问任何网页 ...
基于内嵌Tomcat的应用开发 -
phoneeye:
麻烦你,如果是抄来的文章,请给出来源。谢谢
ant 两则技巧 -
neverforget:
转载不注明出处
Spring Security3.1登陆验证 替换 usernamepasswordfilter -
liang1022:
若不使用eclipse ,如何在命令行下 运行服务端程序 ?
WebService CXF学习(入门篇2):HelloWorld
JSP has been the De facto standard for Java and web development for years. JSP is one of the first popular dynamic web application frameworks. Since then as architecture models have evolved. PHP has taken a foothold in the simple dynamic web applications and large enterprise application with complex business logic has moved to MVC design using Java or .Net. Where does that leave JSP and how does it compare with Velocity and Freemarker?
JSP Overview
Originally, Java Server Pages were designed to be utilized within a J2EE web container that would allow for full application development. Older applications were designed to be written to directly access the JSP files. This is the MVC model 1 architecture approach. The client directly references the JSP page, the JSP page references a bean which in turn can access database information. With today's standards, however, it is typically not acceptable to utilize JSP as an independent architecture solution. As software architecture has evolved and design patterns have changed, it seems that the purposes of JSP pages have changed as well.
The ability of JSP to permit scripting, tags, and html code makes it as powerful as Java itself with the capability to be directly run as a web page. To rebuttal the strength of this point, this unrestricted ability of allowing so many different development techniques is simply dangerous. It becomes dangerous to both the application architecture and to the average developer as it is very easy to introduce inconsistency in design patterns into the JSP. The complexity of JSP can grow quickly and further development or ongoing maintenance could suffer in both time and cost.
An example of abusive JSP development can occur when mixing different JSP syntax. Using an particular tag library with with an expression or using ETL inside and outside of tags. JSP Scriplets are in violation of the MVC approach when using JSP as a view component which is the primary function JSP pages are used today.
Veloctiy and Freemarker Overview
Velocity and Freemarker are template engines that define a template language in which to parse. They take Java objects and merge the data with the template. Velocity and Freemarker are so similar I will not compare one to the other. Both are active projects. Velocity recently came out of its shell after a few slow years and had some releases in 2007. Freemarker may have a few bit more functionality than velocity but is also a bit more complex.
JSP vs Template Engines
* Compile Time - JSP need to be processed and compiled to before it is executed. JSP file is converted to a Java file. It is then compiled into a class file. Both velocity and freemarker do not need compiliation. This is especially beneficial to a developer. Everytime a developer modifies a JSP it is very slow to run it due to compilation. The Velocity engine is named Velocity for a reason.
* Learning Curve - JSP is very large with many tag different libraries. Velocity and Freemarker are simple. The engine and core functionality can be understood within a matter of hours.
* Readibility - JSP allows for tag libraries, scriplets, expression language, and other various techniques that is recognized as code. Velocity uses a short list of built in commands.
* Community Base - Many developers know JSP. It is a very common language for developers to list as a skill. Both freemarker and velocity have a large user base but neither is as large as JSP. This is because JSP was originally used as a full application framework when deployed to a compliant web container.
* Template structure - JSP allows for many different types of syntax. Scripting techniques such as declarations, scriptlets, and expressions as well as actions and tags. Velocity uses a #command for commands and $var for variables. Freemarker uses <#command> for commands and ${var} for variables. JSP 2.0 tries to appear as template engine with ${} trying to resemble template style
* Custom Tools - JSP allows for the creation of JSP taglibs. Both Freemarker and Velocity allow the utilization of JSP taglibs as well. Freemarker has a lot of extra built in functionality as well. Velocity allows the developer to create their own custom tools. These tools are created in Java and utilized as Java objects within the template.
* Integration - Most of the major libraries and development tools integrate with JSP, Velocity and Freemarker. Frameworks such as Sitemesh, Tiles, Struts, and Spring have functionality available to utilize all 3 technologies.
there are couple of things where FreeMarker might suit you better:
1. This is subjective, but the overall syntax is less awkward. I’m aware there’s lot of syntacic sugar in JSP 2.0 that’s aimed at hiding the ugliness of directly using JSTL tags for control flow etc. but remember that FreeMarker has had a rather ergonomic syntax for “foreach” and “if” for years.
2. Macros. If you want to have reusable template snippets, you can write them as macros and import them. AFAIK, in JSP 2.0 you finally have a sort of macros, but you need to define each snippet in its own file. This is nowhere as elegant as the full namespace/macro solution in FreeMarker.
3. Transforms. Transforms are the equivalent of body tags in JSP, with a significant distinction that while JSP body tags first cache all of their body and only after that act on them, FreeMarker transforms are fully output-driven, in fact they are implemented internally as chains of java.io.Writer objects. Therefore, regardless of how many transforms you have nested, you can still have progressive page rendering (“can” because a transform can choose to cache all of its body like a JSP body tag, but is not mandated to do so and can provide a clever implementation that allows progressive processing).
4. Also, the usual argument about usability outside the HTTP protocol stack. If your system does any text output beside HTTP responses – i.e. sends SMTP mail, you can use FreeMarker for generating mail messages from templates, too, or for generating arbitrary XML. It even has declarative XML processing capabilities which make it possible to use it similar to XSLT, but significantly less complex. You can simplify your project by having one language for all your text output generating needs.
5. Data model flexibility – if you like, you can implement the data model interfaces to naturally represent any underlying data model. I.e. we have a wrapper for Jython objects that pretty faithfully reflects the look and feel of Jython objects in the template syntax. People have reported providing a similar binding for JavaScript etc.
There’s also lots of goodies like automatic HTML or XML escaping of expressions, convenient literal syntax for lists and maps, etc.
This much off the top of my head – it’s a bit late here, so I can’t think of anything else at this very moment.
Velocity's Simplistic design
Of the three technologies, velocity is the simplest. It has a small amount of very powerful commands. Syntax is as follows.
Display variable name
$var
Display variable name. If null it displays blank
$!var
Directives
#foreach ($item in $collection) item is $item #end
#if ($order.total == 0) No charge #end
#parse("header.vm")
#macro
#include("disclaimer.txt")
#set ($customer = ${order.customer})
Code Comparisons
Here is some code that is written in JSP. This is the logic that would be used when processing a number named "number" is passed in as a parameter.
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<!-- Is the number guess right? -->
<logic:equal parameter="number" value="7">
You guessed right! You win a high speed blender!
</logic:equal>
<!-- If the number guessed was wrong -->
<logic:notEqual parameter="number" value="7">
<!-- Less Than -->
<logic:lessThan parameter="number" value="7">
A little higher...
</logic:lessThan>
<!-- Greater Than -->
<logic:greaterThan parameter="number" value="7">
A little lower...
</logic:greaterThan>
</logic:notEqual>
And here is the same logic within a velocity template
<!-- Is the number guess right? -->
#if ( $number == 7 )
You guessed right! You win a high speed blender!
#end
<!-- If the number guessed was wrong -->
#if ( $number != 7 )
<!-- Less Than -->
#if ( $number < 7 )
A little higher...
<!-- Greater Than -->
#elseif ( $number > 7 )
A little lower...
#end
#end
Now a another example with the same task. Create a list and display it. First JSP.
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%
java.util.ArrayList list = new java.util.ArrayList();
list.add("First");
list.add("Second");
list.add("Third");
list.add("Fourth");
list.add("Fifth");
pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
%>
<logic:iterate id="myCollectionElement" name="list">
Element Value: <bean:write name="myCollectionElement" /><br />
</logic:iterate>
And here is the velocity version.
#set ( $list = ["First", "Second", "Third", "Fourth", "Fifth"] )
#foreach ( $item in $list )
Element Value: $item<br />
#end
Conclusion
JSP has provided developers with a very useful library and toolset. It has been around for a long time and there are no signs that its users are declining. Due to MVC style architecture, server side processing including business logic should not take place within the view component. I did not get into Velocity vs Freemarker debate since they are identical from an architectural standpoint. You can make that decision by comparing the template language itself and choose which is better suited for your needs. When determining which technology to utilize I hope that you take time to research each technology and use this article as a reference.
发表评论
-
Java keytool 安全证书学习笔记
2012-08-02 14:16 811http://linliangyi2007.iteye.com ... -
java国际化
2012-07-16 14:08 432http://lavasoft.blog.51cto.com/ ... -
Java版远程控制V1.0
2012-06-17 21:37 779http://www.cnblogs.com/syxchina ... -
浅析Java中CountDownLatch用法
2012-05-16 20:57 809CountDownLatch如其所写,是一个 ... -
SMTP发送邮件
2012-04-18 09:41 785SMTP发送邮件 openkk 2011-06-0 ... -
smtp 返回代码 信息
2012-04-18 08:52 1461SMTP Server Response Cod ... -
JavaMail详解
2012-04-18 02:24 0JavaMail详解 博客分类: JAV ... -
安装Eclipse反编译插件
2012-04-17 09:34 813安装Eclipse反编译插件 博客分类: ... -
Java编程中“为了性能”尽量要做到的一些地方
2012-04-13 08:30 676最近的机器内存又爆满了,除了新增机器内存外,还应该好好r ... -
Dijkstra算法
2012-04-11 08:00 879Dijkstra算法 博客分类: 算 ... -
java 播放音乐
2012-04-11 08:00 1010java 播放音乐 博客分类: J2 ... -
Java中的native,transient,volatile和strictfp关键字
2012-04-06 08:49 743Java中的native,transient,v ... -
用ReentrantLock模拟宴会的热闹情景
2012-04-05 08:32 916用ReentrantLock模拟宴会的热闹情景 ... -
Hashmap 分析
2012-04-05 08:32 741Hashmap 博客分类: 算法 ... -
ExecutorService线程池
2012-04-05 08:32 773ExecutorService线程池 (2010 ... -
Java并发:juc Executor框架详解
2012-04-05 08:32 796Java并发:juc Executor ... -
java并发包,多线程,工具类,笔记
2012-04-11 08:00 925JDK 线程池 Executors.newCachedT ... -
利用 Spring 和 EHCache 做方法缓存处理〔转〕
2012-04-09 09:49 864利用 Spring 和 EHCache 做方法缓存处理〔 ... -
EhCache使用详细介绍
2012-04-09 09:49 1361EhCache使用详细介绍 Ehcache中不仅可 ... -
HashMap 分析
2012-04-01 08:21 1921http://www.blogjava.net ...
相关推荐
- **多视图选项**:无缝集成了多种视图选项,如JSP/JSTL、Tiles、Velocity、FreeMarker等。 - **易于测试**:依赖注入使得单元测试变得简单。 #### 缺点: - **用户基数相对较小**:相比于Struts,使用Spring MVC的...
内容概要:本文深入剖析了安川MP7系列工业控制系统的关键源码,重点介绍了运动轨迹规划、通信协议处理以及故障处理机制等方面的技术细节。通过对实际代码片段的解读,揭示了该系统在硬件寄存器直接访问、特殊功能码处理等方面的独特之处。同时,文中还分享了一些基于实践经验得出的重要参数设置及其背后的故事,如特定摩擦补偿系数的选择原因等。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是对安川产品有一定了解并希望深入了解其内部工作机制的专业人士。 使用场景及目标:帮助读者掌握安川MP7系列控制器的工作原理,提高对类似系统的维护能力和故障排查效率。对于想要进一步研究或二次开发该系统的开发者来说,也能提供宝贵的参考资料。 其他说明:文章不仅限于理论讲解,还包括了许多来自一线的实际案例和经验教训,使读者能够更好地理解和应用所学知识。
自动化测试与脚本开发_Python3_pynput_键盘鼠标操作录制执行代码生成工具_用于自动化测试_脚本录制_重复操作模拟_宏命令生成_提高工作效率_支持GUI界面_跨平台兼容_
嵌入式八股文面试题库资料知识宝典-深入分析Windows和Linux动态库应用异同.zip
嵌入式八股文面试题库资料知识宝典-C语言总结.zip
内容概要:本文详细探讨了风储直流微电网中母线电压控制的关键技术。首先介绍了风储直流微电网的背景和发展现状,强调了母线电压控制的重要性。接着阐述了永磁风机储能并网技术,解释了永磁风机如何通过直接驱动发电机将风能转化为电能,并确保与电网的同步性和稳定性。然后深入讨论了双闭环控制MPPT技术,这是一种通过内外两个闭环控制系统来实现实时调整发电机运行参数的技术,确保风机始终处于最大功率点附近。最后,文章探讨了储能控制母线电压平衡的方法,即通过储能系统的充放电操作来维持母线电压的稳定。结论部分指出,通过这些技术的有机结合,可以实现对风储直流微电网的有效管理和优化控制。 适合人群:从事新能源技术研发的专业人士、电气工程研究人员、风电系统工程师。 使用场景及目标:适用于希望深入了解风储直流微电网母线电压控制策略的研究人员和技术人员,旨在帮助他们掌握最新的控制技术和方法,以提高系统的稳定性和效率。 其他说明:文章还对未来风储直流微电网的发展进行了展望,指出了智能化和自动化的趋势,以及储能技术的进步对系统性能的影响。
嵌入式八股文面试题库资料知识宝典-C++object-oriented.zip
内容概要:文章详细介绍了HarmonyOS的目录结构及其重要性,从整体框架到核心目录的具体功能进行了全面剖析。HarmonyOS凭借其分布式架构和跨设备协同能力迅速崛起,成为全球操作系统领域的重要力量。文章首先概述了HarmonyOS的背景和发展现状,强调了目录结构对开发的重要性。接着,具体介绍了根目录文件、AppScope、entry和oh_modules等核心目录的功能和作用。例如,AppScope作为全局资源配置中心,存放应用级的配置文件和公共资源;entry目录是应用的核心入口,负责源代码和界面开发。此外,文章还对比了HarmonyOS与Android、iOS目录结构的异同,突出了HarmonyOS的独特优势。最后,通过旅游应用和电商应用的实际案例,展示了HarmonyOS目录结构在资源管理和代码组织方面的应用效果。; 适合人群:具备一定编程基础,尤其是对移动操作系统开发感兴趣的开发者,包括初学者和有一定经验的研发人员。; 使用场景及目标:①帮助开发者快速理解HarmonyOS的目录结构,提高开发效率;②为跨设备应用开发提供理论和技术支持;③通过实际案例学习资源管理和代码组织的最佳实践。; 其他说明:HarmonyOS的目录结构设计简洁明了,模块职责划分明确,有助于开发者更好地管理和组织代码和资源。随着万物互联时代的到来,HarmonyOS有望在开发便利性和生态建设方面取得更大进展,吸引更多开发者加入其生态系统。
内容概要:本文详细介绍了飞轮储能充放电控制的Simulink仿真模型,重点在于采用永磁同步电机的矢量控制和dq轴解耦控制策略。充电时,外环控制转速,内环控制dq轴电流;放电时,外环控制直流母线电压,内环同样控制dq轴电流。文中还讨论了硬件与软件环境的选择,以及仿真模型的调试与运行情况,最终得出该模型具有良好的跟随性能和波形完美度。 适用人群:从事电力电子系统、储能技术和Simulink仿真的研究人员和技术人员。 使用场景及目标:适用于需要对飞轮储能系统进行深入研究和仿真的场合,旨在提高充放电效率和稳定性,满足不同应用场景的需求。 其他说明:该仿真模型已调试完成,可以直接用于进一步的研究和实际应用,为未来的飞轮储能技术研发提供了有价值的参考。
嵌入式八股文面试题库资料知识宝典-北京瑞德方科技.zip
嵌入式八股文面试题库资料知识宝典-同方万维硬件测试工程师.zip
1_15套python PDF格式.zip
内容概要:本文详细介绍了三相三电平整流器的仿真过程及其性能分析。文中首先概述了三相三电平整流器的基本概念及其在电力系统中的重要作用,接着重点探讨了电压电流双闭环控制方式的工作原理和优势,以及SPWM调制技术的具体应用。通过仿真文件展示了整流器在不同条件下的响应情况,验证了这两种技术的有效性和优越性。最后,作者表达了对未来实际应用的期望。 适合人群:从事电力电子研究的技术人员、高校相关专业师生、对电力控制系统感兴趣的工程爱好者。 使用场景及目标:适用于希望深入了解三相三电平整流器工作原理和技术细节的研究人员;目标是在理论基础上掌握电压电流双闭环控制和SPWM调制的实际应用方法。 其他说明:本文提供的仅为仿真文件,未涉及实物实验数据。
嵌入式八股文面试题库资料知识宝典-恒光科技.zip
嵌入式八股文面试题库资料知识宝典-北京天华威视科技有限公司面试题.zip
嵌入式八股文面试题库资料知识宝典-微软研究院笔试题目的答案.zip
Arduino UART实验例程,开发板:正点原子EPS32S3,本人主页有详细实验说明可供参考。
嵌入式八股文面试题库资料知识宝典-朝歌数码.zip
嵌入式八股文面试题库资料知识宝典-Cortex系列.zip
嵌入式八股文面试题库资料知识宝典-中科中科长青笔试题.zip