Solved

tags questions

Posted on 2003-11-06
6
257 Views
Last Modified: 2010-04-01
1.What is the difference beween thes two and what differing effect will they have on the page an system
2.in what situation would you use one or the other

<%!
int a = 0
%>

and

<%
int a = 0
%>


0
Comment
Question by:danBosh
6 Comments
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
1. this is homework
2. read your book
3. <%! is for method/class declaration
4. <% this stuff goes into doGet()/doPost() when converted to servlet (which all jsps are)
0
 

Author Comment

by:danBosh
Comment Utility
its not home work, im 22 and a IT consultant
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 20 total points
Comment Utility
ok, well then 3 and 4 answer your question anyway.

ie:

<%!
   private String saySomething(String s) {
      return s;
   }
%>

try and do the above w/o the !

<%
   out.println(saySomething("Hello World")); // this gets executed automatically on page load
%>
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 27

Expert Comment

by:rrz
Comment Utility
I agree with everything that bobbit31 posted.
Also,
the scriptlet is thread safe, but the declaration is not safe because it is inserted into the main body of the servlet class.  
The declaration is a place to store data that is persistent between requests.
You can put a inner class in a declaration.
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
One more thing.
You could use a declaration to override the jspInit and jspDestroy methods of your JSP.
0
 
LVL 3

Expert Comment

by:applekanna
Comment Utility
Just a note ... though not any different from the other posts...

<%!
int a = 0
%>

when the JSP is converted to servelt code by the engine it put this seperately like a method in your program that can be accesed from anywhere.

<%
int a = 0
%>     is duplicated in the servcice() method of the servelt as is where is

Hope this helps
Cheers!

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now