• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replace scriptlet

 
Kumaraguru Narayanan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

<%
List list = new ArrayList();
list.add("Abc");
list.add("Xyz");
%>

Please help me in replacing the scriptlet with standard actions and EL...

Kumaraguru
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: use [] operator of EL
 
Thirugnanam Saravanan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is it possible to add elements to a List using [] operator of EL? If so please clarify how.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumaraguru Narayanan wrote:
<%
List list = new ArrayList();
list.add("Abc");
list.add("Xyz");
%>
Please help me in replacing the scriptlet with standard actions and EL...



Hi Kumaraguru,

first of all, dont do business logic in jsp. setting the datas in a list should come in java class or servlet . then set the list into the session|request scope and forward it to your success jsp page. then for displaying the data use jstl|EL .

Hope this helps
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: use [] operator of EL

Do you think it will work ? Basically, EL is used to read data.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:first of all, dont do business logic in jsp.


Yes. Here is the crux of the matter. The purpose of the JSTL and EL isn't just to replace scriptlets with a different syntax to do inappropriate things on a page, it's to urge (even force) people to design or refactor their web apps using modern best practices.

When replacing scriptlets with JSTL/EL there isn't always a one-to-one correspondence -- and there shouldn't be! It's an opportunity to evaluate what you are doing on your JSP and decide if it is appropriate or not, and if not, refactor.

If you can't do something on your page easily with the JSTL and EL, chances are it's because of a design flaw.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL is for expression, not for business procession.

Consider to put business logic in Servlet or POJO.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic