What is the proper way to call a servlet from a facelets file using a form with submit button? Is there a particular form required?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just use a plain HTML
<form>instead of a JSF<h:form>. The JSF<h:form>sends by default a POST request to the URL of the current view ID and invokes by default theFacesServlet. It does not allow you to change the form action URL or method. A plain HTML<form>allows you to specify a different URL and, if necessary, also the method.The following kickoff example sends a search request to Google:
Note that you do not need to use JSF components for the inputs/buttons as well. It is possible to use
<h:inputText>and so on, but the values won’t be set in the associated backing bean. The JSF component overhead is then unnecessary.When you want, for example, to send a POST request to a servlet which is mapped to a URL pattern of
/foo/*and you need to send a request parameter with the namebar, then you need to create the form as follows:This way the servlet’s
doPost()method will be invoked: