You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tim Funk <fu...@joedog.org> on 2003/09/15 15:28:29 UTC

Re: pageContext.forward ??

I have no clue based on the current info but
1) Make sure your repsonse is committed before forward. This will be obvious 
if you see and IllegalStateException
2) Make sure there is not another page (resource,..) performing another 
redirect or similar
3) Is your custom tag returning Tag.SKIP_PAGE to ensure the rest of your JSP 
page is ignored? If not - is your JSP page doing anything "wacky"?


-Tim


Julien Martin wrote:

> Hello,
> 
> I am trying to redirect to a servlet called "RedirectHome" from within a
> custom tag.
> 
> Within the tag class, I have a method called "redirect". This method is
> called when a certain condition is met.
> 
> I know the method is called thanks to the trace but oddly the
> pageContext.forward appears to be ignored. I think I had it working on a 2.3
> container but I won't work on the new 2.4 container...
> 
> Can anyone help?
> 
> Here is the code for the "redirect" method:
> 
> *********************************************
>  public void redirect() {
> System.out.println("redirect called");
> try {
>                                      pageContext.forward("RedirectHome");
> }
> catch (ServletException e) {
>                                          e.printStackTrace();
> }
> catch (IOException e) {
>                                          e.printStackTrace();
> }
> 
> }
> *********************************************
> 
> I use Tomcat 5.0
> 
> Julien.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


Thank you Tim (re pageContex.forward)

Posted by Julien Martin <ju...@wanadoo.fr>.
Thank you Tim,
Thanks very much for your help.  That sorted it.
Julien.

----- Original Message -----
From: "Tim Funk" <fu...@joedog.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, September 15, 2003 4:11 PM
Subject: Re: pageContext.forward ??


> 1) See the FAQ, there is a question dedicated to IllegalStateException
> 2) If you are doing a .forward() the rest of the JSP page SHOULD BE
IGNORED.
> Otherwise - you have a bad coding style. The stuff executing in your JSP
> after the forward is doine inside the custom tag is probably doing bad
things
> 3) Its not a redirect - your are doing a forward. The 2 words have very
> different meanings. forward() is an internal redirect. Redirect is
typically
> stated as an external browser redirect
> 4) See 2
>
> -Tim
>
> Julien Martin wrote:
>
> > Thanks for your reply Tim,
> >
> > 1. What do you mean by committing the response?  Can you give me more
> > details?
> > 2. I can't skip the page since my tag needs to be at the top of the jps
> > page.
> > 3. There is only one resource performing a redirect.
> > 4. I have included the whole tag class for your information.
> >
> > Julien.
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


Re: pageContext.forward ??

Posted by Tim Funk <fu...@joedog.org>.
1) See the FAQ, there is a question dedicated to IllegalStateException
2) If you are doing a .forward() the rest of the JSP page SHOULD BE IGNORED. 
Otherwise - you have a bad coding style. The stuff executing in your JSP 
after the forward is doine inside the custom tag is probably doing bad things
3) Its not a redirect - your are doing a forward. The 2 words have very 
different meanings. forward() is an internal redirect. Redirect is typically 
stated as an external browser redirect
4) See 2

-Tim

Julien Martin wrote:

> Thanks for your reply Tim,
> 
> 1. What do you mean by committing the response?  Can you give me more
> details?
> 2. I can't skip the page since my tag needs to be at the top of the jps
> page.
> 3. There is only one resource performing a redirect.
> 4. I have included the whole tag class for your information.
> 
> Julien.
> 



pageContext.forward ??

Posted by Julien Martin <ju...@wanadoo.fr>.
Thanks for your reply Tim,

1. What do you mean by committing the response?  Can you give me more
details?
2. I can't skip the page since my tag needs to be at the top of the jps
page.
3. There is only one resource performing a redirect.
4. I have included the whole tag class for your information.

Julien.


************************************
package com.parispano.latinamericaguide;

import java.io.IOException;

import javax.servlet.ServletContext;

import javax.servlet.ServletException;

import javax.servlet.jsp.JspException;

import javax.servlet.jsp.tagext.TagSupport;

/**

* @author Julien Martin

*/

public class SetCountryTag extends TagSupport {

private String countryID = null;

private ServletContext servletContext = null;

public int doStartTag() throws JspException {

try {

Countries cs = (Countries) servletContext.getAttribute("countries");

Country country = new Country();

if (countryID == null || countryID.equals("")) {

System.out.println("-----null ou vide");

redirect();

return 0;

}

int countryIDint = Integer.parseInt(countryID);

country = cs.getCountryFromId(countryIDint);

pageContext.setAttribute("country", country);

} catch (NoCountryFoundException e) {

redirect();

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

return SKIP_BODY;

}

public int doEndTag() {

return EVAL_PAGE;

}

public String getCountryID() {

return (this.countryID);

}

public void setCountryID(String countryID) {

this.countryID = countryID;

}

public ServletContext getServletContext() {

return servletContext;

}

public void setServletContext(ServletContext servletContext) {

this.servletContext = servletContext;

}

public void redirect() {

System.out.println("redirect called");

try {

pageContext.forward("RedirectHome");

} catch (ServletException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

************************************


----- Original Message -----
From: "Tim Funk" <fu...@joedog.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, September 15, 2003 3:28 PM
Subject: Re: pageContext.forward ??


> I have no clue based on the current info but
> 1) Make sure your repsonse is committed before forward. This will be
obvious
> if you see and IllegalStateException
> 2) Make sure there is not another page (resource,..) performing another
> redirect or similar
> 3) Is your custom tag returning Tag.SKIP_PAGE to ensure the rest of your
JSP
> page is ignored? If not - is your JSP page doing anything "wacky"?
>
>
> -Tim
>
>
> Julien Martin wrote:
>
> > Hello,
> >
> > I am trying to redirect to a servlet called "RedirectHome" from within a
> > custom tag.
> >
> > Within the tag class, I have a method called "redirect". This method is
> > called when a certain condition is met.
> >
> > I know the method is called thanks to the trace but oddly the
> > pageContext.forward appears to be ignored. I think I had it working on a
2.3
> > container but I won't work on the new 2.4 container...
> >
> > Can anyone help?
> >
> > Here is the code for the "redirect" method:
> >
> > *********************************************
> >  public void redirect() {
> > System.out.println("redirect called");
> > try {
> >
pageContext.forward("RedirectHome");
> > }
> > catch (ServletException e) {
> >                                          e.printStackTrace();
> > }
> > catch (IOException e) {
> >                                          e.printStackTrace();
> > }
> >
> > }
> > *********************************************
> >
> > I use Tomcat 5.0
> >
> > Julien.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>