This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 15961
    
  19

"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
 
Similar Threads
Call to JSF experts
File downloading
problem in retrieving the parameters through request.getParameter()
exception while running code
how to trigger a servlet from JSF