Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call servlet from managed bean jsf

 
Steeve Randria
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Steeve Randria
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help

Finally, I decided to go through the couple JSP / Servlet thanks to a form and it works well
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic