You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dola Woolfe <do...@yahoo.com> on 2005/11/04 20:14:19 UTC
Can a "return" statement cause a problem?
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.
Thanks!
Dola Chin
__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Can a "return" statement cause a problem?
Posted by Dola Woolfe <do...@yahoo.com>.
> >What could that be? In the tomcat console window, I
> >get no indication that something is not right.
> >
> >
> >
>
> First you still should be presenting a well formed
> HTML page to the
> browser. I think I'm correcting in stating that
> <META ...> should
> exiting inside <HEAD>, but you still should emit
> </HEAD><BODY></BODY></HTML>.
Well, actually I gett the same error (500) when I use
wget instead of a browser, so it's not HTML (although
I agree that HTML ought to be proper).
I like your suggestions that follow, but at this point
I'm also wondering where I could find some kind of an
error message to see what goes wrong. I know that the
return statement is reached and once my JSP has no
control, I don't know how to monitor what happens
next!
Thanks,
Dola
>
> Second are you sure you want to do your HTTP
> redirect like this ?
> Conceptually by the time you are rendering a JSP
> page your that Servlet
> has made a decision that this JSP page (and
> therefore this View) is the
> correct one the user should see. I am presuming
> that you might not have
> any customer Servlet infront of this JSP page and
> are using the
> defaultServlet to get there. Maybe its worth you
> creating a Servlet and
> moving the Java Code logic into that. Then doing a
> "forward" to the JSP
> page you wish to render, or setup a HTTP redirect to
> force the browser
> to goto another URL.
>
> My thoughts.
>
> I'm not sure if return is right or wrong here from a
> specification
> standpoint.
>
> --
> Darryl L. Miles
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Can a "return" statement cause a problem?
Posted by "Darryl L. Miles" <da...@netbauds.net>.
Dola Woolfe wrote:
>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.
>
>
>
First you still should be presenting a well formed HTML page to the
browser. I think I'm correcting in stating that <META ...> should
exiting inside <HEAD>, but you still should emit
</HEAD><BODY></BODY></HTML>.
Second are you sure you want to do your HTTP redirect like this ?
Conceptually by the time you are rendering a JSP page your that Servlet
has made a decision that this JSP page (and therefore this View) is the
correct one the user should see. I am presuming that you might not have
any customer Servlet infront of this JSP page and are using the
defaultServlet to get there. Maybe its worth you creating a Servlet and
moving the Java Code logic into that. Then doing a "forward" to the JSP
page you wish to render, or setup a HTTP redirect to force the browser
to goto another URL.
My thoughts.
I'm not sure if return is right or wrong here from a specification
standpoint.
--
Darryl L. Miles
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Can a "return" statement cause a problem?
Posted by Dola Woolfe <do...@yahoo.com>.
Sorry, forgot to paste.
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import html.*;
public final class ErrorPage_jsp extends
org.apache.jasper.runtime.HttpJspBase
implements
org.apache.jasper.runtime.JspSourceDependent {
private static java.util.Vector _jspx_dependants;
public java.util.List getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
Throwable exception =
org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);
if (exception != null) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this,
request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write('\r');
out.write('\n');
String offendingPage =
request.getAttribute("javax.servlet.error.request_uri")
+ "?" + request.getQueryString();
try {
if (exception instanceof
servlets.Authentication.Exception) {
System.out.println("I'm here!!!!");
out.println("<html>" + new
Forward("/applicaitona/LoginForm.jsp?Forward=" +
offendingPage.replaceAll("&", "AMERSAND"), 0) +
"</html>");
////////////////////////////////////////////////////////////////////////
return;
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
}
else {
String uri = (String)
request.getAttribute("request_uri");
String url = "http://projectc" +
request.getAttribute("javax.servlet.error.request_uri")
+ "?" + request.getQueryString();
String body = "The error occurred when viewing the
following page:\n" + url + "\n\nMy Comments:\n ";
body = body.replaceAll("&", "%26").replaceAll(" ",
" ").replaceAll("%", "%25").replaceAll("\n",
"%0D%0A");
//
// body = java.net.URLEncoder.encode(body);
Table table = new Table()
.pAddH("Date").pAddL(new java.util.Date()).pLN()
.pAddH("Info").pAddL("An error has occurred, but
now we capture errors gracefully. If you belive that
this is a Project A error, please " +
new
Anchor("mailto:pg@Companyinvest.com?Subject=Project A
Problem&Body=" + body, "ALERT PG by emailing him") +
".").pLN()
.pAddH("Possible Resolution")
.pAddL("For what it's worth, I'm passing to you
the name of the error produced by java, " +
"which may give you some indication of what was
wrong:<br> " + new Text.Bold(exception)).pLN()
.pAddH("What to do next")
.pAddL("Visit the " + new
Anchor("/applicaitona/TroubleShooting.jsp",
"Troubleshooting") + "page to find out whether this is
a common problem.").pLN()
.pAddH("Emergency").pAddL("If this is an emergency
contact PG at (917) 699 5105").pLN()
;
table.pAddH("The following section<br>is intended
for PG").pSetSpan(1, 2).pLN();
StackTraceElement[] ste =
exception.getStackTrace();
for (int i = 0; i < ste.length; i++) {
String className = ste[i].getClassName();
if (className.startsWith("database") ||
className.startsWith("contrib") ||
className.startsWith("html") ||
className.startsWith("servlets") ||
className.startsWith("universe")) {
String fileName = ste[i].getFileName();
int n = ste[i].getLineNumber();
String name = "C:/User/ProjectA/src/" +
className.substring(0,
className.lastIndexOf('.')).replace('.', '/')+ "/" +
ste[i].getFileName();
Anchor emacsAnchor = new Anchor(name,
fileName);
Anchor htmlAnchor = new
Anchor("UtilTextFileInATable.jsp?FileName=" +
name.replaceAll("/", "\\\\") + "&Highlight=" + n,
"(HTML View)");
table.pAddH("" + i).pAddL(emacsAnchor + ",
line " + n + " " + htmlAnchor).pLN();
} else if (className.endsWith("_jsp")) {
String fileName = ste[i].getFileName();
fileName =
fileName.substring(fileName.lastIndexOf('.') + 1) +
".java";
int n = ste[i].getLineNumber();
// String name =
"C:/User/tomcat/work/DEFAULT/applicaitona/" +
fileName;
String name =
"C:/User/tomcat/work/Catalina/localhost/applicaitona/org/apache/jsp/"
+ fileName;
Anchor emacsAnchor = new Anchor(name,
fileName);
Anchor htmlAnchor = new
Anchor("UtilTextFileInATable.jsp?FileName=" +
name.replaceAll("/", "\\\\") + "&Highlight=" + n,
"(HTML View)");
table.pAddH("" + i).pAddL(emacsAnchor + ",
line " + n + " " + htmlAnchor).pLN();
}
else
table.pAddH("" + i).pAddL(ste[i].getClassName()
+ " " + ste[i].getMethodName() + " " +
ste[i].getFileName() + ", line " +
ste[i].getLineNumber()).pLN();
}
CompanyTemplate template = new CompanyTemplate("An
Error Has Occurred", table);
Page pAgE = new Page(new CompanyFeel.Head("An
Error Has Occurred"), new Body(template));
out.print(pAgE);
}
}
catch (Exception e) {
e.printStackTrace();
}
out.write('\r');
out.write('\n');
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Can a "return" statement cause a problem?
Posted by Dola Woolfe <do...@yahoo.com>.
--- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
> 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.
Here's the entire generated file and the troubling
"return" is surrounded surrounded by forward slashes.
Thanks!
__________________________________
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
Re: Can a "return" statement cause a problem?
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
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 <bo...@sequoiallc.com> wrote:
>
>> On Fri, 4 Nov 2005 11:14:19 -0800 (PST)
>> Dola Woolfe <do...@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
Re: Can a "return" statement cause a problem?
Posted by Dola Woolfe <do...@yahoo.com>.
--- Bob Bateman <bo...@sequoiallc.com> wrote:
> On Fri, 4 Nov 2005 11:14:19 -0800 (PST)
> Dola Woolfe <do...@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
Re: Can a "return" statement cause a problem?
Posted by Bob Bateman <bo...@sequoiallc.com>.
On Fri, 4 Nov 2005 11:14:19 -0800 (PST)
Dola Woolfe <do...@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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org