JSF: How to forward a request to another page in action?
- by Satya
I want to forward request to another page from action class
I am using below code in my jsf action :
public String submitUserResponse(){
......
......
parseResponse(uri,request,response);
....
return "nextpage";
}
public String parseResponse(String uri,request,response){
if(uri != null){
RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
dispatcher.forward(request, response);
return null;
}
.................
..................
return "xxxx";
}
"submitUserResponse" method is being called when user clicks the submit button from the jsp
and this method returns "nextpage" string here request forwards to next page in normal flow.
but in my requirement i will call "submitUserResponse () " which will execute and forwrd request to next page.It is going. but it is displaying some exceptions in server
That is :
java.lang.IllegalStateException: Cannot forward after response has been committed
Here my doubts are:
1.why next lines of code is being executed after forwarding my request using dispatched.forward(uri) . Same thing happening in response.sendRedirect("").