i'm new to jsp so this is probably a basic question.
I'm just wondering if the jsp xml syntax is something everyone should shift to, or is it a case to case basis?
Oh, it hasn't really got anything to do with conforming to xml, or a dtd.
Your first example (<% %>) is called a scriptlet tag - here you can embed Java code to be compiled by the container (eg Tomcat). Some people say you shouldn't use scriptlets as they should be in their own classes, some don't.
The second "xml syntax" (standard tag library)(<jsp:useBean .../>) is another way of using Java components, but in a more "html coder /scripter friendly way" - and it is the *desired* form for some.
To be honest, there are times when using scriptlets makes sense, and times when they don't. For example, you don't want to connect to a databse using scriptlet tags, but you may want to control the colours of an html <table> rows using a simple scriptlet loop.
In my experience, you should aim to go for the second tag library option, unless it means going to extraordinary lengths to do something that could be done in 2 minutes in a scriptlet.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.