aspose file tools*
The moose likes JSF and the fly likes Call servlet from managed bean jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Call servlet from managed bean jsf" Watch "Call servlet from managed bean jsf" New topic
Author

Call servlet from managed bean jsf

Steeve Randria
Greenhorn

Joined: Sep 17, 2010
Posts: 16
Hello,

I have a jsf page which includes an inputText and a button.
I would call a servlet at the click of the button, display the value of the InputText filled , and redisplay the same jsf page with inputText filled.

The fields of my jsf page



My function that calls the servlet in the managed bean



And my servlet



The problem is that once we get to the servlet, the redirection to the jsf page does not work, I have a stackoverflow error:
at dispatcher.forward(request, response) method

Thank you for your help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

"forward" doesn't mean "call". When you call something, it returns to you. When you forward, it doesn't return.

If the servlet is located internal to the same webapp as JSF, "calling" the servlet is probably a bad idea. If there is code in the servlet that JSF code needs, it's usually cleaner to have JSF call the code directly via ordinary Java method calls. Ideally, the shared code will be in a distinct shareable business logic bean rather than in the servlet class itself.

JSF and traditional servlets/JSPs can happily reside side-by-side, and they can pass data between each other via session and application-scope beans.


Customer surveys are for companies who didn't pay proper attention to begin with.
Steeve Randria
Greenhorn

Joined: Sep 17, 2010
Posts: 16
Thank you for your help

Finally, I decided to go through the couple JSP / Servlet thanks to a form and it works well
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call servlet from managed bean jsf