JSP - scriptlet 有什么问题,以及使用什么代替 [英] JSP - What is wrong with scriptlets, and what to use instead

查看:14
本文介绍了JSP - scriptlet 有什么问题,以及使用什么代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年前我在一本书中读到过 JSP,最近决定自学.我现在知道如何使用 JSP 脚本、表达式和声明

I read about JSP in a book many years ago, and recently decided to learn on my own. I now know how to use JSP scriptlets, expressions, and declarations

    <%! String str = "Hello World" %>
    <%= str.length() %>
    <% str=str.substring(0,5) %>

但是我在很多地方(在本网站和其他地方)都读到过我不应该使用 scriptlet.这是一个这样的问题:Eclipse using Classes in JSP

But I have read in many places (on this site and elsewhere) that I shouldn't use scriptlets. This is one such question: Eclipse using Classes in JSP

我的问题是:

  1. scriptlet 有什么问题?
  2. 我用什么代替?

在此先感谢您的帮助!

我不使用 Servlet,而是将我的 JSP 代码嵌入到 HTML 页面中.不了解 Java 的 UI 设计人员可以轻松修改我的页面.基本上,我使用 JSP 作为前端,用于从数据库显示并对其进行更新,例如在用户下订单时.

I do not use Servlets, but embed my JSP code onto an HTML page. UI designers with no knowledge of Java can easily modify my page. Basically I use JSP as a front end for displaying from a database and making updates to it such as when a user makes an order.

推荐答案

这当然是我个人的意见.我说脚本是:

This is my personal opinion, of course. I say scriptlets are:

  1. 一种需要消失的 1998 年复古技术;对 Microsoft ASP 的失败响应.
  2. 难以阅读
  3. 难以维护
  4. 不鼓励重用和封装
  5. 鼓励在页面中放置复杂的逻辑

用什么代替?

  1. 世界已经朝着 HTML5、CSS3、JavaScript、jQuery、Bootstrap 以及与 REST 网络服务对话的网络技术的方向发展.这是一个很好的方向.
  2. 如果您必须坚持使用 JSP,请从 JSP 标准模板库开始.让您的 HTML 页面看起来像 HTML - 这将使 UI 开发人员更容易维护它们.
  3. 尝试使用更现代的模板解决方案,例如 Thymeleaf,从服务器端生成 HTML.

这篇关于JSP - scriptlet 有什么问题,以及使用什么代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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