dcsimg
How do I redirect from a included servlet to another jsp page.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, August 13, 2002 08:18 AM

Hi all. I´m tring something like this. I have a a.jsp which has: The method register checks so there isn´t to many users allready. If there are to many users I want to redirect user to another page, b.jsp. So far I tried: 1: RequestDispatcher rd; rd = getServletContext().getRequestDispatcher( "b.jsp" ); rd.forward( req, res ); Error: java.lang.IllegalStateException: Cannot forward after response has been committed 2: res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); res.setHeader("Location", "b.jsp" ); Error: Browser shows a.jsp    More>>

Hi all.

I´m tring something like this.

I have a a.jsp which has:

			





The method register checks so there isn´t to many users allready. If there are to many users
I want to redirect user to another page, b.jsp. So far I tried:


1:
			
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher( "b.jsp" );
rd.forward( req, res );

Error: java.lang.IllegalStateException: Cannot forward after response has been committed



2:
			
res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
res.setHeader("Location", "b.jsp" );

Error: Browser shows a.jsp



3:
			
res.sendRedirect( res.encodeRedirectURL( "b.jsp" ) );
return;

Error: Browser shows a.jsp



Nothing seems to work for me. Any suggestion how to solve this? Help is appreciated.

Regards Tobias    <<Less

Re: How do I redirect from a included servlet to another jsp page.

Posted By:   Erik_Runia  
Posted On:   Tuesday, August 13, 2002 01:05 PM

for scenario #1 i may have an answer:



be sure you havent assigned a printwriter to your response object and printed anything to it, if you have it will no longer allow you to forward to a page because you have allready started writing the response manually.


Hope this helps,


Erik

About | Sitemap | Contact