This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes Difference between declarative and scriptlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSP
Bookmark "Difference between declarative and scriptlet" Watch "Difference between declarative and scriptlet" New topic

Difference between declarative and scriptlet

Jayanth Mathavan

Joined: Nov 10, 2005
Posts: 16
Am a bit confused about the functionality of a declarative tag and a scriptlet tag.
example of a declarative is <%! int x=10; %>
and Scriplet is <% public void method1(int x, int y){ int a = x+y; } %>

Can we use java codes inside a declarative tag? If so, then whats the difference between a declarative tag and a scriptlet tag?

Thanks and Regards,
Jayanth Mathavan.
[ August 16, 2007: Message edited by: Jayanth Mathavan ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63211

I must preface this by stating that at this point in time, you should be using JSP 2.0 and shouldn't be using either of the declarations or scriptlets in your pages any longer.

That said, scriptlets are code fragments that are collected to form the service method of the JSP along with the statements needed to emit the template text.

Declarations are placed at class-level rather than within a method.

Declarations are the easiest way to introduce threading bugs into yout JSP pages and should be avoided unless absolutely necessary even in older JSP versions.
[ August 16, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Difference between declarative and scriptlet
It's not a secret anymore!