• Post Reply Bookmark Topic Watch Topic
  • New Topic

newbie question: valid or good jsp code  RSS feed

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a newbie question.
Is the following valid or good jsp code?
Please help me to improve it.
Thanks.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's obvious that you know about <c:forEach> -- why would you not use it for the inner loop as well? What's with the scriptlet?

Any Java code or Java scriplets in the JSP is bad.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To tell you the truth: horrible ;-) ...

But don't worry ... the concept is easy ..

never ever use scriptlets in JSPs ... It's just a matter of separating concerns ... Instead of using a scriptlet for you loop simply use another JSTL tag. You will see that your code looks much more organized afterwards.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate being late !!! ;-)
 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:It's obvious that you know about <c:forEach> -- why would you not use it for the inner loop as well? What's with the scriptlet?

Any Java code or Java scriplets in the JSP is bad.


Is this ok?
$alert is an ArrayList<String>.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Much nicer! Don't you agree?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!