tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: Can a "return" statement cause a problem?
Date Fri, 04 Nov 2005 20:05:28 GMT
It might be interesting to look at the class file generated from your
JSP... many times things like this become fairly obvious when you see the
code that is actually being executed.

Also, if your using a JSP 2.0 container, you may be interested in playing
with tag files:

http://today.java.net/pub/a/today/2003/11/14/tagfiles.html

Kind of a good first step for playing with custom tags without quite as
much work.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Fri, November 4, 2005 3:00 pm, Dola Woolfe said:
>
>
> --- Bob Bateman <bobbateman@sequoiallc.com> wrote:
>
>> On Fri, 4 Nov 2005 11:14:19 -0800 (PST)
>>   Dola Woolfe <dolachin@yahoo.com> wrote:
>> > Hi,
>> >
>> > In one of my JSP pages (ErrorPage.jsp) I have the
>> > following code.
>> >
>> > <%
>> > if (display-nothing-only-forward) {
>> >  out.println("<META to forward to another page in
>> 0
>> > seconds>");
>> >  // return;
>> > }
>> >
>> > //Lot's more code
>> > %>
>> >
>> > It works, but prints out unnecessary html before
>> it
>> > forwards. But if I uncomment "return" it stops
>> > working. I get
>> > HTTP 500 - Internal server error
>> >
>> > What could that be? In the tomcat console window,
>> I
>> > get no indication that something is not right.
>>
>> I would postulate that you are executing unnecessary
>> code.
>>
>> *Disclaimer: The following is NOT compliant with MVC
>> best
>> practices...
>>
>> In your JSP page, you *probably* want your "if
>> (display-nothing-only-forward)" statement to execute
>> if
>> there is nothing to do.  If that is true, then after
>> your
>> closing brace with the META info in it, you probably
>> want
>> to use an 'else' clause and enclose the rest of your
>> code
>> in a set of braces.
>>
>> In effect, what you've done is to tell the system to
>> put
>> the META statement out ONLY when there is nothing
>> else to
>> do - but the rest of your code runs all the time.
>>
>> If you have sufficient experience, I would suggest
>> removing all of the java code from your JSP page and
>>
>> putting the code into a Tag.  Tags are really easy
>> to use
>> and keep your business logic seperate from your JSP
>> presentation.  Of course, you'll still have to
>> generate
>> HTML in the Tag, but that's partly what tags are
>> for.
>>
>> Bob
>>
> Hi Bob,
>
> I have not used Tags and plan to take a look at them
> soon.
>
> Concerning the rest of your suggestion, having a big
> "else" clause is precisely something I'm trying to
> avoid. I always prefer
>
> if (short_clause) {
>   //...
>   return;
> }
>
> //rest of code
>
> to
>
> if (short_clause) {
>   //...
>   return;
> }
> else {
> //rest of code
> }
>
> Also, what I'm curious about is this; what I do may
> not be a good coding practice, but what is causing the
> error?
>
> Thanks!
>
> Dola
>
>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>>
>>
>
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message