Solved

tags questions

Posted on 2003-11-06
6
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stateless EJB with glassfish 2 73
maven project jars 7 58
countXY challenge 28 171
withoutString  challenge 40 215
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Building a cohesive image for your brand is vital to making an impression on consumers. When the economy is tough, brands do better than unbranded  products. This can have a huge impact on your long-term profits, as the economy goes up and down.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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