Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I redirect to an external URL from a Button (h:commandButton)?

843844Dec 1 2009 — edited Dec 1 2009
I would like to redirect to an external URL (something like http://www.google.com) when the user pushes a button.

I can change this to link if I have to, but I would like to keep it as a button to be consistent with other parts of the application.

Any suggestions or links to references?
Thanks.

I tried using things like:
            FacesContext context = FacesContext.getCurrentInstance();
            HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
            response.sendRedirect(sb1.getGoToURL());
but that gives me a page error:
Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error. 

Exception Details: java.lang.IllegalStateException 
  PWC1227: Cannot forward after response has been committed

Possible Source of Error: 
   Class Name: org.apache.catalina.core.ApplicationDispatcher 
   File Name: ApplicationDispatcher.java 
   Method Name: doForward 
   Line Number: 400 

Source not available. Information regarding the location of the exception can be identified using the exception stack trace below. 
 

Stack Trace: 

org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:400)
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
 <...snip...>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2009
Added on Dec 1 2009
3 comments
1,514 views