?
Solved

<%!  %> doubt in jsp

Posted on 2003-02-25
14
Medium Priority
?
253 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
[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
  • 5
  • 4
  • 2
  • +2
14 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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