• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Scriplets

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I keep hearing that scriplets are bad way of coding.Is it true?If it is, then where do I write the code?

Thanks.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code that is typically crammed in a JSP page is either (a) presentation logic or (b) business logic.

In the case of presentation logic, this can be coded in a custom JSP tag class, or a Java servlet.

In the case of business logic, this can be coded in a plain old business object or a Session EJB, or a Web service.

Keep in mind that a Java Server Page is a Java servlet.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put your code in a servlet, pass beans that contain things you want on your page to a JSP, and use JSTL and the Expression Langauge (EL) in the JSP to display the data.

Quick example. Assume this code in the doGet/doPost:



Then index.jsp would look like:



You can, of course, set multiple attributes, and they can be more complicated than strings (example, a collection of objects/JavaBeans obtained from a database). The JSTL and EL provide mechanism to extract data from collections and any JavaBean. By doing this you can avoid server-side script within JSPs.
[ October 08, 2008: Message edited by: Peter Johnson ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic