You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ryan Littrell <ry...@v-1.com> on 2000/10/03 20:06:18 UTC

sendRedirect Error 500 in java component

I ran across a problem when doing a redirect in a component outside of the
jsp. I get a object has moved and a error code 500. Has anyone else ran
across this problem?

Below is an example of my code.


-- JSP Page Start --
<jsp:useBean id="bean" scope="request" class="test.TestBean"/>
<% bean.check(request, response); %>
-- JSP Page End --


-- Java Component Start --
...
public void check(HttpServletRequest request, HttpServletResponse response)
{
   response.sendRedirect(response.encodeRedirectURL("/index.jsp"));
}
...
-- Java Component End --




The only way I was able to fix this was to do this.



-- JSP Page Start --
<jsp:useBean id="bean" scope="request" class="test.TestBean"/>
<% if(bean.check(request, response)) return; %>
-- JSP Page End --


-- Java Component Start --
...
public boolean check(HttpServletRequest request, HttpServletResponse
response) {
   response.sendRedirect(response.encodeRedirectURL("/index.jsp"));
   return true;
}
...
-- Java Component End --


I also tried setting the status to SC_OK and flushing the buffer after I did
the redirect to no avail.

I welcome your ideas.

Thanks, 
Ryan