Lumia
Lumia

Reputation: 121

How to call servlet from JSF?

How to call servlet from JSF.If i want to call any servlet from page like index.xhtml then how can i do that? When user click on any link or button at that time i want to call servlet file instead of any bean file.

Upvotes: 1

Views: 4143

Answers (1)

BalusC
BalusC

Reputation: 1108742

Use a normal HTML <form> pointing to the URL of that servlet instead of a JSF <h:form>. Use normal HTML <input> elements instead of JSF <h:inputXxx> components.

<form action="servletURL" method="post">
    <input type="text" name="foo" />
    <input type="text" name="bar" /> 
    <input type="submit" />
</form>

So, just the same plain 'ol HTML/Servlet way without any JSF form and input components in the view. It's not different in a Facelets page than in a normal HTML or legacy JSP page.

I however wonder if you aren't totally missing the point of JSF here. It might be worth the effort to re-ask the question in the form of how to achieve the particular functional requirement with JSF.

Upvotes: 3

Related Questions