JSTL有哪些替代方案?

时间:2022-11-29 15:59:57

Are there any alternatives to JSTL? One company I worked for 3 years ago used JSTL and custom tag libraries to separate presentation from logic. Front-end developers used EL to do complex presentation logic, generate layouts in JSP pages and it worked out great. Perhaps new technologies have come out. Anything better these days?

JSTL还有其他选择吗?我在3年前工作过的一家公司使用JSTL和自定义标记库将表示与逻辑分开。前端开发人员使用EL来执行复杂的表示逻辑,在JSP页面中生成布局,并且效果很好。也许新技术已经问世。这几天有什么好转的?

6 个解决方案

#1


17  

JSTL and EL are two distinct concepts.

JSTL和EL是两个截然不同的概念。

JSTL is just one tag library. Most frameworks provide their own taglib that approximately duplicates the functionality of JSTL. I say approximately, because these often misuse or overlook key principles of JSP and the Servlet API.

JSTL只是一个标记库。大多数框架都提供了自己的taglib,它大致复制了JSTL的功能。我大致说,因为这些经常滥用或忽略JSP和Servlet API的关键原则。

The strength of JSTL is that it was designed by the authors of JSP, with a solid understanding of JSP and servlets. Third-party taglibs are often created by some guy who didn't want to RTFM and decided to "start from scratch" and come up with "something simpler". However, JSTL wasn't intended to do everything. It can be used very successfully in conjunction with other taglibs, including your own custom tags.

JSTL的优势在于它是由JSP的作者设计的,对JSP和servlet有着深刻的理解。第三方标签库通常由一些不想RTFM的人创建,并决定“从头开始”并提出“更简单的东西”。但是,JSTL无意做任何事情。它可以非常成功地与其他标记库一起使用,包括您自己的自定义标记。

Expression language is fundamental to JSP. It is interpreted by the container, and can be used in many contexts. It is also largely side-effect free, and has a simple, easily comprehensible syntax that doesn't allow a lot of logic to get stuffed into the presentation layer. Being part of the Java EE spec, it also enjoys wide tool support. For example, many IDEs can refactor dependent EL expression when you rename a property.

表达式语言是JSP的基础。它由容器解释,并且可以在许多上下文中使用。它也基本上没有副作用,并且具有简单,易于理解的语法,不允许将大量逻辑填充到表示层中。作为Java EE规范的一部分,它还享有广泛的工具支持。例如,重命名属性时,许多IDE可以重构依赖的EL表达式。

Struts2 introduced OGNL to a wider audience. OGNL is a throwback to the evil days of scriptlets. It is more powerful, and so developers happily abuse it to invoke arbitrary methods in the presentation layer and other atrocities. Attackers happily exploit it too; it is a common source of vulnerabilities in Struts2-based applications.

Struts2向更广泛的受众介绍了OGNL。 OGNL是对小脚本邪恶时代的回归。它更强大,因此开发人员乐于滥用它来调用表示层和其他暴行中的任意方法。攻击者也乐意利用它;它是基于Struts2的应用程序中常见的漏洞来源。

I was familiar with OGNL from years of previous experience with WebWork, and my greatest disappointment in Struts2 was the failure to jettison this dreck. Even WebWork founder, Patrick Lightbody, acknowledges that adoption was a mistake.* Luckily, it can only be used in limited contexts, like OGNL-aware tags (and some other surprising places), unlike EL, which is supported by the container itself and can be used anywhere in a page.

我很熟悉OGNL多年以前的WebWork经验,而我对Struts2的最大失望是没能抛弃这个残骸。甚至WebWork的创始人Patrick Lightbody都承认采用是一个错误。*幸运的是,它只能在有限的环境中使用,比如OGNL感知标签(和其他一些令人惊讶的地方),不像EL,它由容器本身和可以在页面中的任何位置使用。

If you want to get away from JSP, but aren't into a component-based approach like JSF, you might check out Terrence Parr's StringTemplate project. The focus there is to be side-effect–free, which gives valuable improvements to safety and scalability.

如果你想远离JSP,但不是像JSF这样的基于组件的方法,你可以查看Terrence Parr的StringTemplate项目。重点是无副作用,这为安全性和可扩展性提供了有价值的改进。

* QFT: After a successful attack on the Struts2-based Apple Developer site, Patrick Lightbody said, "Sadly, I feel some responsibility for this pretty major security hole. There have been a few like this and they are all rooted in the fact that almost 9 years ago I made the (bad) decision to use OGNL as WebWork's expression language. I did so because it was 'powerful' but it opened up all sorts of extra binding trickery I never intended."

* QFT:在成功攻击基于Struts2的Apple开发者网站后,Patrick Lightbody说:“可悲的是,我对这个相当重要的安全漏洞负有责任。有一些像这样的事情,他们都根植于这样一个事实:差不多9年前,我决定使用OGNL作为WebWork的表达语言。我之所以这么做是因为它“强大”,但它开辟了我从未想过的各种额外绑定技巧。“

#2


6  

I've used velocity with great success and it works great as a simple way to separate business logic from presentation logic. And it's simple enough that your average web developer can understand it. Freemarker is another templating alternative that a lot of people like, as well.

我使用了速度非常成功,它作为一种将业务逻辑与表示逻辑分离的简单方法,效果很好。而且很简单,您的普通Web开发人员可以理解它。 Freemarker是很多人喜欢的另一种模板替代品。

#3


3  

JSTL is a tag library containing logic functions that can be used inside a JSP page. Other such libraries also exist, but most probably you want to look at revised approaches to the whole jsp/jstl solution.

JSTL是一个包含逻辑函数的标记库,可以在JSP页面中使用。其他类似的库也存在,但很可能你想看看整个jsp / jstl解决方案的修订方法。

Most notably I would recommend looking at:

最值得注意的是我建议看看:

Apache Wicket

JSF with facelets

JSF与facelets

Google Web Toolkit (GWT)

Google Web Toolkit(GWT)

#4


3  

JSTL encourages you to put logic in your UI. Try Apache Wicket instead where logic is done in java.

JSTL鼓励您在UI中放置逻辑。尝试Apache Wicket而不是在java中完成逻辑。

#5


1  

Assuming you're looking for an easier way to develop an application using MVC I would highly recommend looking at the Spring Framework. Spring has its own tag lib that provides most of what you should need in the JSPs. I have had great success using Spring webflow along with the Spring forms tag lib. I like to divide the application up into a persistence layer (using Spring's ORM support for Hibernate), a service layer (business logic), and a view layer. The view layer includes the web flows, JSPs, and POJOs for validations and actions. I have also used DWR in the view layer for AJAX calls.

假设您正在寻找使用MVC开发应用程序的更简单方法,我强烈建议您查看Spring Framework。 Spring有自己的标记库,它提供了JSP中你需要的大部分内容。我使用Spring webflow以及Spring表单标记库取得了巨大的成功。我喜欢将应用程序划分为持久层(使用Spring对Hibernate的ORM支持),服务层(业务逻辑)和视图层。视图层包括用于验证和操作的Web流,JSP和POJO。我还在视图层中使用DWR进行AJAX调用。

#6


0  

I won't say they're a replacement or alternative, but I think Java-Server-Faces go a step further in separation presentation from logic...

我不会说它们是替代品或替代品,但我认为Java-Server-Faces在逻辑分离表示方面更进了一步......

#1


17  

JSTL and EL are two distinct concepts.

JSTL和EL是两个截然不同的概念。

JSTL is just one tag library. Most frameworks provide their own taglib that approximately duplicates the functionality of JSTL. I say approximately, because these often misuse or overlook key principles of JSP and the Servlet API.

JSTL只是一个标记库。大多数框架都提供了自己的taglib,它大致复制了JSTL的功能。我大致说,因为这些经常滥用或忽略JSP和Servlet API的关键原则。

The strength of JSTL is that it was designed by the authors of JSP, with a solid understanding of JSP and servlets. Third-party taglibs are often created by some guy who didn't want to RTFM and decided to "start from scratch" and come up with "something simpler". However, JSTL wasn't intended to do everything. It can be used very successfully in conjunction with other taglibs, including your own custom tags.

JSTL的优势在于它是由JSP的作者设计的,对JSP和servlet有着深刻的理解。第三方标签库通常由一些不想RTFM的人创建,并决定“从头开始”并提出“更简单的东西”。但是,JSTL无意做任何事情。它可以非常成功地与其他标记库一起使用,包括您自己的自定义标记。

Expression language is fundamental to JSP. It is interpreted by the container, and can be used in many contexts. It is also largely side-effect free, and has a simple, easily comprehensible syntax that doesn't allow a lot of logic to get stuffed into the presentation layer. Being part of the Java EE spec, it also enjoys wide tool support. For example, many IDEs can refactor dependent EL expression when you rename a property.

表达式语言是JSP的基础。它由容器解释,并且可以在许多上下文中使用。它也基本上没有副作用,并且具有简单,易于理解的语法,不允许将大量逻辑填充到表示层中。作为Java EE规范的一部分,它还享有广泛的工具支持。例如,重命名属性时,许多IDE可以重构依赖的EL表达式。

Struts2 introduced OGNL to a wider audience. OGNL is a throwback to the evil days of scriptlets. It is more powerful, and so developers happily abuse it to invoke arbitrary methods in the presentation layer and other atrocities. Attackers happily exploit it too; it is a common source of vulnerabilities in Struts2-based applications.

Struts2向更广泛的受众介绍了OGNL。 OGNL是对小脚本邪恶时代的回归。它更强大,因此开发人员乐于滥用它来调用表示层和其他暴行中的任意方法。攻击者也乐意利用它;它是基于Struts2的应用程序中常见的漏洞来源。

I was familiar with OGNL from years of previous experience with WebWork, and my greatest disappointment in Struts2 was the failure to jettison this dreck. Even WebWork founder, Patrick Lightbody, acknowledges that adoption was a mistake.* Luckily, it can only be used in limited contexts, like OGNL-aware tags (and some other surprising places), unlike EL, which is supported by the container itself and can be used anywhere in a page.

我很熟悉OGNL多年以前的WebWork经验,而我对Struts2的最大失望是没能抛弃这个残骸。甚至WebWork的创始人Patrick Lightbody都承认采用是一个错误。*幸运的是,它只能在有限的环境中使用,比如OGNL感知标签(和其他一些令人惊讶的地方),不像EL,它由容器本身和可以在页面中的任何位置使用。

If you want to get away from JSP, but aren't into a component-based approach like JSF, you might check out Terrence Parr's StringTemplate project. The focus there is to be side-effect–free, which gives valuable improvements to safety and scalability.

如果你想远离JSP,但不是像JSF这样的基于组件的方法,你可以查看Terrence Parr的StringTemplate项目。重点是无副作用,这为安全性和可扩展性提供了有价值的改进。

* QFT: After a successful attack on the Struts2-based Apple Developer site, Patrick Lightbody said, "Sadly, I feel some responsibility for this pretty major security hole. There have been a few like this and they are all rooted in the fact that almost 9 years ago I made the (bad) decision to use OGNL as WebWork's expression language. I did so because it was 'powerful' but it opened up all sorts of extra binding trickery I never intended."

* QFT:在成功攻击基于Struts2的Apple开发者网站后,Patrick Lightbody说:“可悲的是,我对这个相当重要的安全漏洞负有责任。有一些像这样的事情,他们都根植于这样一个事实:差不多9年前,我决定使用OGNL作为WebWork的表达语言。我之所以这么做是因为它“强大”,但它开辟了我从未想过的各种额外绑定技巧。“

#2


6  

I've used velocity with great success and it works great as a simple way to separate business logic from presentation logic. And it's simple enough that your average web developer can understand it. Freemarker is another templating alternative that a lot of people like, as well.

我使用了速度非常成功,它作为一种将业务逻辑与表示逻辑分离的简单方法,效果很好。而且很简单,您的普通Web开发人员可以理解它。 Freemarker是很多人喜欢的另一种模板替代品。

#3


3  

JSTL is a tag library containing logic functions that can be used inside a JSP page. Other such libraries also exist, but most probably you want to look at revised approaches to the whole jsp/jstl solution.

JSTL是一个包含逻辑函数的标记库,可以在JSP页面中使用。其他类似的库也存在,但很可能你想看看整个jsp / jstl解决方案的修订方法。

Most notably I would recommend looking at:

最值得注意的是我建议看看:

Apache Wicket

JSF with facelets

JSF与facelets

Google Web Toolkit (GWT)

Google Web Toolkit(GWT)

#4


3  

JSTL encourages you to put logic in your UI. Try Apache Wicket instead where logic is done in java.

JSTL鼓励您在UI中放置逻辑。尝试Apache Wicket而不是在java中完成逻辑。

#5


1  

Assuming you're looking for an easier way to develop an application using MVC I would highly recommend looking at the Spring Framework. Spring has its own tag lib that provides most of what you should need in the JSPs. I have had great success using Spring webflow along with the Spring forms tag lib. I like to divide the application up into a persistence layer (using Spring's ORM support for Hibernate), a service layer (business logic), and a view layer. The view layer includes the web flows, JSPs, and POJOs for validations and actions. I have also used DWR in the view layer for AJAX calls.

假设您正在寻找使用MVC开发应用程序的更简单方法,我强烈建议您查看Spring Framework。 Spring有自己的标记库,它提供了JSP中你需要的大部分内容。我使用Spring webflow以及Spring表单标记库取得了巨大的成功。我喜欢将应用程序划分为持久层(使用Spring对Hibernate的ORM支持),服务层(业务逻辑)和视图层。视图层包括用于验证和操作的Web流,JSP和POJO。我还在视图层中使用DWR进行AJAX调用。

#6


0  

I won't say they're a replacement or alternative, but I think Java-Server-Faces go a step further in separation presentation from logic...

我不会说它们是替代品或替代品,但我认为Java-Server-Faces在逻辑分离表示方面更进了一步......