Posting a JSF page to Servlet
There are some use cases which requires posting data to a (legacy) Servlet for further processing and on success, redirect to a JSF page. This example illustrates a possible solution for similar scenarios - posting a JSF page to a Servlet. Basic idea is to invoke a custom javascript method on click of the button and submit the form to a customized 'action' target(Servlet).
[Runs with Oracle JDeveloper 11g R1 PS2]
How to run this sample?
Run the login.jspx page. This page is pre-populated with values for user name and password fields, leave the default values as is. Click on 'Post Me' button. This in turn posts data to 'SampleServlet' which processes the posted data, and on success, request is getting redirected to welcome.jspx
<af:commandButton text="Post Me" id="cb1">
<af:clientListener type="action" method="customPostHandler"/>
</af:commandButton>
<af:resource type="javascript">
function customPostHandler(event) {
var form = document.forms[0];
form.action = '/some-context-root/sampleservlet';
form.submit();
event.cancel();
}
</af:resource>
You can download the sample workspace from here.[Runs with Oracle JDeveloper 11g R1 PS2]
How to run this sample?
Run the login.jspx page. This page is pre-populated with values for user name and password fields, leave the default values as is. Click on 'Post Me' button. This in turn posts data to 'SampleServlet' which processes the posted data, and on success, request is getting redirected to welcome.jspx
Thanq It helped a lot.
ReplyDeleteThis is an important article. I read like this type of article only. You mentioned more important points about technology. Thankyou.
ReplyDeletecore java training in chennai
Best core java Training in Chennai
core java Training in OMR
C Training in Chennai
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
core java training in chennai