JSTL与JSP Scriptlets [英] JSTL vs JSP Scriptlets

查看:163
本文介绍了JSTL与JSP Scriptlets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人在这个问题中解释BlausC的惊人答案中的一些要点/ a>。

I want someone to explain some points in BlausC's amazing answer in this question.

他说scriptlet有一些缺点,包括:

He said that scriptlets had some disadvantages, which are:


  1. 可重用性:您无法重用scriptlet。我的问题:我如何重用JSTL代码?

  1. Reusability: you can't reuse scriptlets. My question : how could I reuse JSTL code?

可替换性:你不能使scriptlet抽象化。抽象意味着什么以及JST如何变得抽象?

Replaceability: you can't make scriptlets abstract. What does abstract mean and how could JST become abstract?

OO:你不能使用继承/组合。我如何在JSTL中使用OO范例?

OO: you can't make use of inheritance/composition. How could I use OO paradigms in JSTL?

调试:如果一个scriptlet中途抛出一个异常,你得到的只是一个空白页。

Debugging: if a scriptlet throws an exception halfway, all you get is a blank page.

可测试性:无法对scriptlet进行单元测试。这意味着什么,以及如何对JSTL进行单元测试?

Testability: scriptlets can't be unit tested. What does that mean, and how can JSTL be unit tested?

可维护性:每个saldo,需要更多时间来维护混杂/混乱/重复的代码逻辑。这是什么意思?

Maintainability: per saldo, more time is needed to maintain mingled/cluttered/duplicated code logic. What does this mean?

最后一件事是他引用甲骨文的建议:

The last thing is what he quoted form Oracle's recommendation:


JSP scriptlet不应用于编写业务逻辑。

JSP scriptlets should not be used for writing business logic.

In在MVC模式中,我只在表示层使用scriptlet。他在这里的含义是什么?

In the MVC pattern, I use scriptlets only in the presentation layer. What does he mean here?

推荐答案

您似乎只关注脚本的表示和流控制部分,就像使用一样 if switch 语句和 out.print()事情。您似乎将Scriptlet 1:1与JSTL进行比较。这是错的。我不是只谈论流控制部分(实际上是由JSTL取代),而是关于在JSP文件中编写原始Java代码。即收集请求参数,验证和转换值,与数据库和其他Java类/方法交互等等。您通常(间接)在Servlet或Filter中执行的所有操作。

You seem to concentrate on only the presentation and flow-control part of the scriptlets as in using if, for and switch statements and out.print() things. You seem to compare scriptlets 1:1 with JSTL. This is wrong. I was not talking about the flow control part only (which is indeed to be replaced by JSTL), but about writing raw Java code in JSP files in general. I.e. gathering request parameters, validating and converting values, interacting with database and other Java classes/methods, etc. All things you normally (indirectly) do in a Servlet or Filter.

这篇关于JSTL与JSP Scriptlets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆