Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:38:55+00:00 2026-06-12T00:38:55+00:00

I want to send data between two applications by using JSON and Ajax. For

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:38:56+00:00Added an answer on June 12, 2026 at 12:38 am

    You’re mixing servlets and JSF backing beans. They have nothing to do with each other. The TestBean class which you’ve there is in essence a servlet, not a JSF backing bean. You cannot use it by registering it as a JSF managed bean by @ManagedBean on the class or <managed-bean> in faces-config.xml. It has to be registered as a fullworthy servlet. You can use the @WebServlet annotation on the class or the <servlet> entry in web.xml for this.

    Assuming that your environment supports Servlet 3.0, just use @WebServlet to register it:

    @WebServlet("/testservlet")
    public class TestServlet extends HttpServlet {
        // ...
    }
    

    (here, /testservlet, is the URL pattern on which the servlet has to listen)

    and, assuming that /Project1 is the context path, invoke it as

    http://example.com:8080/Project1/testservlet

    (it’d be easier if you test it first by entering the URL straight in browser’s address bar)

    See also:

    • How to use Servlets and Ajax?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing application which send and receive data between two computers but there
I want to send 'packets' of data (i.e. discrete messages) between two programs through
i want to send arabic data from servlet using HTTPServletResponse to client i am
I want to send a large amount of cached json data from an import
i want a two communication between server and Android. From Android want to send
My program uses UDP to send data between two programs, it works great however
I am using Csharp tcp sockets to send data between a client and server.
I wish to send a contiguous array of memory between two nodes using MPI.
So i'm trying to pass data between two views (first view is tableViewController,when cell
I want to attempt to calculate how much data (bytes) I send/receive over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.