Solved

tags questions

Posted on 2003-11-06
6
265 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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