Link to home
Start Free TrialLog in
Avatar of surabhiag
surabhiag

asked on

<%! %> doubt in jsp

If we are declaring the variable and methods than where it goes. Where it is stored in the back end?
Thanks
surabhi
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

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?

https://www.experts-exchange.com/Web/Web_Languages/JSP/
Avatar of surabhiag
surabhiag

ASKER

<%!

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.
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.)
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
When the _jspService() method comes into the picture?.
We also have _jspInit() and _jspDestroy() method.
thanks
Where is the question here?  I see question marks, but no actual question.
ASKER CERTIFIED SOLUTION
Avatar of SuperKarateMonkey
SuperKarateMonkey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much "SuperKarateMonkey".
Now i got it what happens in the back end.
Thank you
That's actually short for "SuperKarateMonkeyDeathCar."  ;)

Don't forget to close the question by accepting an answer.
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
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.
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