Jsp with scriptlets, taglib or jstl

Asked

Viewed 396 times

1

Hello, I just registered and is being my first question. Sorry for any rule I’m not following with this post.

Well, a little while ago I started learning jsp in college, a little bit of scriptlet was introduced (I think that’s <% %>) and taglib () and a lot of jstl. I couldn’t find all the answers to my questions, even here in the stack in both English and Portuguese, but I ended up seeing some people not recommending using scriptlet, because you can’t reuse the code, etc. Some saying not to use only jstl and some other things. That’s when I was confused, after all what is the best practice? Use scriptlet, jstl or mix everything? I even saw people not recommending more jsp, because jsf stopped using it as the default template. Thank you!

  • Here has a people saying that it can replace JSP and that it is only being maintained for legacy applications.

  • That’s not what I understood from that reply, but anyway...

1 answer

0


I think there are several paths that you can follow, talk of development and application building is very broad, some examples would be action-based and Component-based applications, but both of them exist certain patterns that you can follow, Java is very wide you mode even make a miscellany of technologies that would work(could have serious problems but in a basic app you would render), but render is not all, when you start developing your application it will become larger and you get to see the problems you have to solve, whether performance, layout, integrations etc... when you write many scriptlets on the JSP page itself you are taking a responsibility that should be on the Java server for your JSP which is where only your HTML code should be, the fact is that due to this permissive breadth that Java has ends up making developers do everything that is m. in a software.

Scriptlets should not be on the JSP pages because it is not the responsibility of the designer to know Java or even the page developers, but these days and speaking now of JSF which are components-based applications you no longer depend so much on the designer, well likely that if you use JSF you will choose one of these market Beans like Primefaces, richfaces(over), Icefaces, etc... yet it is possible to merge JSTL and other libraries, but remembering that you have facelets.

But anyway, following the standards is good because it means that many have gone through the same problems that you’ll face if you don’t follow them, resulting in a bad model, believe me, it’s pretty easy for a project to fail and one wrong decision in it is enough to be doomed to failure, so study, whether to study and make good use of the Patterns, but not because of the fad of the time, but because that pattern really solves a problem in a very elegant way and that above all it matches the principles of design.

  • Yes, I was at home for work when I started writing, I also knew someone would raise this question :), but that’s not how I wanted to express myself, I also did not want to comment that a JSP turns into a Servlet etc... because the subject would go too far, wanted to just emphasize how bad it is to have Java code in the middle of all HTML, but you’re sure there are more processes in request/Answer.

  • removed the part where I quoted it, thanks for the feed-back on pointing out the error.

  • So scriptlet really shouldn’t be used, it’s best to have only JSTL in JSP and whatever Java code is has to be directed to Servlet?

  • exactly @Tadeu F.I and in case of being JSF in the current versions is not good use with JSP and yes . xhtml because the life cycle of JSP does not match well with faces.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.