Solved

tags questions

Posted on 2003-11-06
6
260 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
ID: 9694837
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
ID: 9694873
its not home work, im 22 and a IT consultant
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 20 total points
ID: 9695067
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 27

Expert Comment

by:rrz
ID: 9696482
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
ID: 9696533
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
ID: 9698715
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
As a business owner, there are many things that keep you up at night. Profit margins, employee retention, human resource protocols, whether your product or service will remain competitive. When you own or manage a technology company that operates la…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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