JSTL 与 JSP Scriptlets [英] JSTL vs JSP Scriptlets

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

问题描述

我希望有人在 这个问题.

他说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?

可替换性:你不能让脚本变得抽象.抽象是什么意思,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?

最后一件事是他从 Oracle 的建议中引用的内容:

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

不应使用 JSP 脚本来编写业务逻辑.

JSP scriptlets should not be used for writing business logic.

在 MVC 模式中,我只在表示层使用 scriptlet.他在这里是什么意思?

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

推荐答案

你似乎只专注于 scriptlet 的表示和流程控制部分,就像使用 if, forswitch 语句和 out.print() 东西.您似乎将 scriptlets 1:1 与 JSTL 进行比较.这是错误的.我不只是在谈论流控制部分(确实会被 JSTL 取代),而是在谈论在 JSP 文件中编写原始 Java 代码的一般情况.IE.收集请求参数、验证和转换值、与数据库和其他 Java 类/方法交互等.您通常(间接)在 Servlet 或过滤器中执行的所有操作.

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天全站免登陆