JSP - scriptlet出了什么问题,以及使用什么 [英] JSP - What is wrong with scriptlets, and what to use instead
问题描述
我多年前在一本书中阅读了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) %>
但是我在很多地方(在这个网站和其他地方)读过我不应该使用scriptlets 。这是一个这样的问题: 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
我的问题是:
My questions are:
- scriptlets有什么问题?
- 我用什么来代替?
预先感谢您的帮助!
我不使用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:
- 1998年的复古技术需要消失;对微软ASP的失败响应。
- 丑陋
- 难以阅读
- 难以维护 >
- 阻止重用和封装
- 鼓励在页面中添加复杂的逻辑
- A 1998 vintage technology that needs to disappear; a failed response to Microsoft's ASP.
- Ugly
- Hard to read
- Hard to maintain
- Discourage reuse and encapsulation
- Encourage putting complex logic in pages
用什么来代替?
What to use instead?
- 世界已经走向HTML5,CSS3,JavaScript,jQuery,Bootstrap和Web技术与REST Web服务交流的方向。这是一个很好的方向。
- 如果您必须坚持使用JSP,请从JSP标准模板库开始。保持HTML页面看起来像HTML - 它将使UI开发人员更容易维护它们。
- 尝试一种更现代的模板解决方案(如Thymeleaf)以从服务器端生成HTML。 / li>
- The world has gone in the direction of HTML5, CSS3, JavaScript, jQuery, Bootstrap, and web technologies talking to REST web services. It's a good direction.
- If you must stick with JSPs, start with the JSP standard template library. Keep your HTML pages looking like HTML - it'll make it easier for UI developers to maintain them.
- Try a more modern template solution like Thymeleaf to generate your HTML from the server side.
这篇关于JSP - scriptlet出了什么问题,以及使用什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!