?
Solved

<%!  %> doubt in jsp

Posted on 2003-02-25
14
Medium Priority
?
258 Views
Last Modified: 2013-11-23
If we are declaring the variable and methods than where it goes. Where it is stored in the back end?
Thanks
surabhi
0
Comment
Question by:surabhiag
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8017490
Not sure I understand...

Some example code might help...

If you mean what I think you mean, session variables and beans are stored in memory by the container

Maybe you'd get more help on the JSP pages?

http://www.experts-exchange.com/Web/Web_Languages/JSP/
0
 

Author Comment

by:surabhiag
ID: 8017636
<%!

int count=0;

public void sample()
{
System.out.println("Sample");
}

%>

if we are delaring in the <% %> tag than code goes to _jspService method. If we are declaring than wher it goes that i want ot know.
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 8017642
You're going to have to be a little more helpful with this question:  What are you talking about?  Do you mean, when declaring a variable/method inside of a <%!...%> tag, where does it get embedded in the code?  Well, in that case:

Background:  All JSP's get compiled to servlets, where all the non-JSP HTML is sent via the HttpServletResponse.getWriter() methods.  So essentially, HTML tags in a JSP get written out to the equivalent servlet code:

BEFORE:
** foobar.jsp **

<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    <b>Bar</b>
  </body>
</html>


AFTER:

public class foobar extends HttpServlet
{

doGet( HttpServletRequest req, HttpServletResponse res )
{
  PrintWriter out = res.getWriter();
  out.println( "<html>" );
  out.println( "<head>" );
  out.println( "<title>Foo</title>" );
  out.println( </head>" );
  out.println( <body>" );
  out.println( "<b>Bar</b>" );
  out.println( "</body>" );
  out.println( "</html>" );
}

}

So, the way the declaration tag in JSP's work:

BEFORE:

<html>
  <head>
    <title>Foo</title>
  </head>
  <%! int new_integer = 0; %>
  <body>
    <b>Bar</b>
  </body>
</html>


AFTER:

public class foobar extends HttpServlet
{

int new_integer = 0;

doGet( HttpServletRequest req, HttpServletResponse res )
{
  PrintWriter out = res.getWriter();
  out.println( "<html>" );
  out.println( "<head>" );
  out.println( "<title>Foo</title>" );
  out.println( </head>" );
  out.println( <body>" );
  out.println( "<b>Bar</b>" );
  out.println( "</body>" );
  out.println( "</html>" );
}

}

The same principle applies to to methods.  They're declared with class scope, so they're visible to everything in the servlet, (or JSP, as the case may be.)
0
Independent Software Vendors: 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!

 

Author Comment

by:surabhiag
ID: 8017719
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
0
 

Author Comment

by:surabhiag
ID: 8017728
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
0
 

Author Comment

by:surabhiag
ID: 8017735
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 8017885
Where is the question here?  I see question marks, but no actual question.
0
 
LVL 2

Accepted Solution

by:
SuperKarateMonkey earned 80 total points
ID: 8017997
OK, some things that should be clear, here:

The service(), doGet(), and doPost() methods can all be considered the same method.  Only one get implemented when the engine recompiles a JSP.  This is b/c doGet(), doPost(), doXxx() etc.. are only convenience methods offered by the HttpServlet class to make programmer's lives easier.

I can only assume that the you're also asking about the JSP-declaration:

<%...%>

This, instead of going outside of the service()/doGet()/doPost() method, actually gets embedded INSIDE of it.  So, in that case:

BEFORE:

<html>
 <head>
   <title>Foo</title>
 </head>
 <% int new_integer = 0; %>
 <body>
   <b>Bar</b>
 </body>
</html>


AFTER:

public class foobar extends HttpServlet
{


service( HttpServletRequest req, HttpServletResponse res )
{
 PrintWriter out = res.getWriter();
 out.println( "<html>" );
 out.println( "<head>" );
 out.println( "<title>Foo</title>" );
 out.println( </head>" );
 int new_integer = 0;
 out.println( <body>" );
 out.println( "<b>Bar</b>" );
 out.println( "</body>" );
 out.println( "</html>" );
}

}

Is this what you're asking?
0
 

Author Comment

by:surabhiag
ID: 8033772
Thank you very much "SuperKarateMonkey".
Now i got it what happens in the back end.
Thank you
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 8034309
That's actually short for "SuperKarateMonkeyDeathCar."  ;)

Don't forget to close the question by accepting an answer.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8038401
ffs...why does it matter?

It works...deal with it....accept SDM's comment, and lets get over this nonsense ;-)

hee hee

I'm gonna post a Q about why adding doubles works, and where EXACTLY in memory all the code is stored...

Tx
0
 

Expert Comment

by:CleanupPing
ID: 9059089
surabhiag:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9671693
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept SuperKarateMonkey's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

621 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