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) %>
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:
- What is wrong with scriptlets?
- What do I use instead?
Thanks in advance for any help!
EDIT:
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.
Answer
This is my personal opinion, of course. I say scriptlets are:
- 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?
- 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.
No comments:
Post a Comment