I want to send data between two applications by using JSON and Ajax. For the first test, i want to click on a button (in xhtml) and receive data in managedbean (in the second application).
For this, i have created :
xhtml page :
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
    <body>
        <ui:composition template="/templates/template.xhtml">
            <ui:define name="content">
                <h:outputScript library="js" name="test.js" />
                <h:form>
                <h:button  onclick="validate();" value="Tester" type="button"/> 
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
    </html>
test.js :
function validate(){ 
    try{
        var myJSONObject = {"name":"hello","address":"xyz"};
        var toServer = "data=" + encodeURIComponent(myJSONObject);
        var request=new XMLHttpRequest();
        request.open("POST", "http://'xxLocalIPxx':8080/Project1/folderTest/TestBean", true);
        request.send(toServer);
        return true;
    }
    catch(err)
    {
    alert(err.message);
    }
};
ManagedBean TestBean :
public class TestBean extends HttpServlet{
    private static final long   serialVersionUID    = 1L;
    public TestBean() {
        super();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // PrintWriter out = response.getWriter();
        String output = request.getParameter("params");
        System.out.println("Servlet : " + output);
    }
}
But, when i click on the button in the xhtml page, i don't execute the method doGet in the managedBean. I tried to put a breakpoint in this method but it never work.
Why ?
Thanks.
 
     
     
    