I admit that the ability of ASP to mix script code and output text markup is
handy... but that's much more of an issue with ASP. JSP provides and even
better approach to this issue. Have a look at taglibs... This allows you
to separate all your markup from logic if you wish. You can mix "output"
tags with JSP tags (that you define, or download from standard common
libraries). These tags can mark blocks that you can repeat or execute
conditionally (for example), and in other cases, act like markers in a
template for data (bit like mail-merge or XSLT if you like).
As such, JSP taglibs let you mix your markup indirectly with your code (you
can avoid including markup directly in methods, yet still be able to decide
whether or not to include that block of markup, and if so, how many times,
and populated with whatever data you like). As it's also externalised your
markup from your code, you can re-use your code yet present it differently
as often as you like. You can even avoid using out.println("") in your
methods as a workaround. Your code is much more readable, practical, and
maintainable. Only downside is that it's not so quick to learn, but it's
not too complicated either.
-Chris
----- Original Message -----
From: "Rob L'Estrange" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 19, 2001 11:50 PM
Subject: Re: Inner scriptlet tags
> Howdy bro
>
> Thanks for you reply. I do have a couple of points to touch on. This is
not
> an argumentitive reply.
>
> I do understand that the method doesn't explicitly see the <out> object
(see
> my second last paragraph starting "I can see that if this were to
work...").
> But instead of outright rejection of the syntax by the translator, what I
> would expect is a complilation error complaining about the non-existance
of
> an <out> variable. In other words, I would expect things to break at the
> compile stage rather than the translation stage. Do you see what I mean?
>
> It all comes back to a conscious decision (by translator implementors) not
> to accept any non-code (or, if you like, any inner scriptlet tags) within
> declaration tags. My guess is that:
> 1. The specification explicitly states that declaration tags cannot
contain
> inner tags; or
> 2. The spec makes no explicit mention on the topic.
>
> I might have to actually read the specs to get the answer from the horse's
> mouth - GULP!! :)
>
> Thanks again.
> Rob
>
> ----- Original Message -----
> From: "iZone Infotech" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, March 17, 2001 1:47 AM
> Subject: Re: Inner scriptlet tags
>
>
> > Dear Rob,
> >
> > If I understand your email correctly, you are interested to know 'why'
> > rather than 'how'.
> >
> > Let me try to explain.
> >
> > Eventhough JSP looks like ASP, the working is not similar. The JSP file
> is
> > compiled into a Java Servlet, the very first time it is executed.
> > Subsequent calls, the Java Servlet is executed, until you make some
> changes
> > in the original JSP file.
> >
> > The whole script you write between <% and %> and the html tags between
> them
> > are compiled together to become part of the service() method of the
> servlet.
> > This method is executed every time a servlet is called.
> >
> > The content in <%! and %> becomes a part outside the sevice(). So your
> > method testMethod() becomes a seperate method outside the service(), in
> the
> > servlet.
> >
> > Now, when you execute the servlet, the service has 2 parameters request
> and
> > response, which takes care of the communication. The Writer is bound to
> the
> > response. In JSP 'out' is the default Writer. All the html you have is
> > equivalent to writing out.print("some html code"). The scope of 'out'
is
> > only within the service() method. the scope of response also is limited
> to
> > the service() method.
> >
> > Since testMethod() being outside service(), that does not understand
'out'
> > or 'response'. In the servlet, your method will look something like
this.
> >
> > testMethod()
> > {
> > out.print("<p align='center'>How are you today?</p>");
> > }
> >
> > This method does not understand 'out', so gives error.
> >
> > The best way to solve the problem is rewriting the method like,
> >
> > String testMethod()
> > {
> > String retStr="<p align='center'>How are you today?</p>";
> > return retStr;
> > }
> >
> > and calling it in the main JSP page as
> >
> > <%= testMethod() %>
> >
> > I have not tried it, so please excuse me if it does not work. But
> logically
> > it should work, and I believe it explains your question. Also, if you
> pass
> > 'out' to the testMethod() and write the method as given above, in the
JSP,
> > it should work(again logically).
> >
> > Best regards,
> >
> > Dantus
> >
> >
> > ----- Original Message -----
> > From: Rob L'Estrange <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Sunday, March 18, 2001 8:02 AM
> > Subject: Re: Inner scriptlet tags
> >
> >
> > > Thanks for your reply Sachin. :)
> > >
> > > You seem to be saying "Well of course you can't do that within
> declaration
> > > tags. Go and read up on JSP tags to improve your understanding" hehe.
> > Thanks
> > > for the advice, but I'm not sure you fully understood my question.
It's
> a
> > > legitimate one I think. Let me expand...
> > >
> > > The supplied syntax is illegal for JSP because JSP translators
> consciously
> > > reject HTML embedded in method declarations. We're in agreement on
> that -
> > > they are built to work that way, no arguments.
> > >
> > > My question is: "Why? Why are the JSP translators built not to accecpt
> > HTML
> > > embedded in method declarations?". I'm not saying that JSP should or
> that
> > it
> > > shouldn't support this syntax; my goal is to understand if there is a
> good
> > > reason why JSP translators work this way. For all I know, there is a
> very
> > > good reason. As mentioned, JSPs primary competitor (ASP) does accept
the
> > > syntax, and this is very handy. And, I do think there is an argument
> along
> > > the lines of, "Well the whole idea of server pages is the blend of
HTML
> > and
> > > code. Why not support HTML embedding even within declarations of
> methods?"
> > >
> > > I can see that if this were to work, the declared method with the
> embedded
> > > HTML would have to have a signature that included a JSPWriter
parameter.
> > > Beyond that, I can't see a barrier to translators being able to handle
> > HTML
> > > embedded in method declarations. But I accept that just because I
cannot
> > see
> > > a problem, that there isn't one. Hence my query to this list.
> > >
> > > What do you think? Is there a good reason why this syntax is not
> > supported?
> > > Or, perhaps, it is supported by some vendors and not others?
> > >
> > > Rob
> > >
> > >
> > > ----- Original Message -----
> > > From: "Sachin S. Khanna" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Friday, March 16, 2001 11:39 PM
> > > Subject: Re: Inner scriptlet tags
> > >
> > >
> > > > Well <! .... > this is a jsp declaration and not a scriptlet.
> > > > There has been a lot of discussion on the difference, use of jsp
> > > declaration
> > > > and scriptlets.
> > > > All of which can be found at the mail archives of this list.
> > > > Please help yourself as well as this list by searching for them out
> > there.
> > > > Have a nice day.
> > > > With regards,
> > > > Sachin S. Khanna.
> > > > www.emailanorder.com
> > > >
> > > > ----- Original Message -----
> > > > From: Rob L'Estrange <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Sunday, March 18, 2001 3:42 AM
> > > > Subject: Inner scriptlet tags
> > > >
> > > >
> > > > > Hi All
> > > > >
> > > > > I've been developing with ASP for sometime and have finally got
> around
> > > to
> > > > > checking out JSP.
> > > > >
> > > > > I've come across something curious. In the source code at the
bottom
> > of
> > > > this
> > > > > email, the highlighted code would be permissible (semantically) in
> ASP
> > > but
> > > > > is not permissible in JSP. I'm using Tomcat 3.2.
> > > > >
> > > > > I understand where the translator is "breaking down" and why - in
> > short,
> > > > the
> > > > > translator has been built not to process scriptlet tags within a
> > > > declaration
> > > > > tag. And I understand that there are ways of achieving the same
> > result,
> > > > and
> > > > > that not all people would see this feature as necessary. But... I
> have
> > > > found
> > > > > the technique useful in ASP development - which is the same as
> saying,
> > > for
> > > > > me at least, the technique is useful in server page development.
Is
> > > there
> > > > a
> > > > > good reason why JSP translators are not built to handle this kind
of
> > > > syntax?
> > > > >
> > > > > Thanks
> > > > > Rob
> > > > >
> > > > > ==================================
> > > > >
> > > > > <%@ page language="Java" %>
> > > > >
> > > > > <%!
> > > > >
> > > > > private void testMethod(){
> > > > > /* Start: Here's the violating code. */
> > > > > %>
> > > > > c > > <%
> > > > > /* End: The violating code. */
> > > > > }
> > > > >
> > > > > %>
> > > > >
> > > > > <html>
> > > > > <head>
> > > > > <title>Hello</title>
> > > > > </head>
> > > > >
> > > > > <body bgcolor="#FFFFFF">
> > > > > <h1 align="center"><font face="Arial"
> > color="#0000FF">Hello</font></h1>
> > > > >
> > > > > <%
> > > > > testMethod();
> > > > > %>
> > > > >
> > > > > </body>
> > > > > </html>
> > > > >
> > > > >
> > > >
> > >
> >
>
===========================================================================
> > > > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > > > JSP-INTEREST".
> > > > > For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST
> > > > DIGEST".
> > > > > Some relevant FAQs on JSP/Servlets can be found at:
> > > > >
> > > > > http://java.sun.com/products/jsp/faq.html
> > > > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> > > > >
> > > >
> > > >
> > >
> >
>
===========================================================================
> > > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > > JSP-INTEREST".
> > > > For digest: mailto [EMAIL PROTECTED] with body: "set
JSP-INTEREST
> > > DIGEST".
> > > > Some relevant FAQs on JSP/Servlets can be found at:
> > > >
> > > > http://java.sun.com/products/jsp/faq.html
> > > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> > >
> > >
> >
>
===========================================================================
> > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> > > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> > DIGEST".
> > > Some relevant FAQs on JSP/Servlets can be found at:
> > >
> > > http://java.sun.com/products/jsp/faq.html
> > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> > >
> >
> >
>
===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.html
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets