aspose file tools*
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 60049

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]
It is sorta covered in the JavaRanch Style Guide.
subject: Difference between declarative and scriptlet
Similar Threads
String Compare
difference between declaration a variable with Expression and without
Rounding up function
Counting the number of hits on a link