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

  • SEARCH
  • Home
  • 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 7806355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:30:30+00:00 2026-06-02T02:30:30+00:00

I am trying to transfer data from a jsp file using a json object.

  • 0

I am trying to transfer data from a jsp file using a json object.

This is my JavaScript code:

// action when item file is clicked
$("li span.file").click(function(){

// get the ID
alert(' Forward the url when clicked WITH ID => ' + $(this).attr('id'));

$.getJSON('BomItemToJSON', function(data) {
    alert('entered getJSON()');
    $.each(data, function(i, item) {
        alert('entered each()');
        var id = item.id;
        var description = item.description;

        alert('description: ' + description);

        formObject = document.forms['itemForm'];
        formObject.elements['itemId'].value = id;
        formObject.elements['itemDescription'].value = description;

        alert('done with javascirpt');
    });
});

});

This is my Servlet which should be called by JavaScript:

public class BomItemToJSON extends HttpServlet {

private static final long serialVersionUID = 1L;

@PersistenceContext(unitName = "xxx")
public EntityManager em;

@Resource
UserTransaction utx;

    Logger logger = Logger.getLogger(this.getClass().getCanonicalName());


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    System.out.println("bom item to json servlet has been called.");
    try {
        utx.begin();
    } catch (NotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //int id = Integer.parseInt(request.getParameter("id"));
    BomHandling bh = new BomHandling(em, utx);

    BomItem item = bh.getBomItem(63788);
    Gson gson = new Gson();
    String json = gson.toJson(item);

    System.out.println("Json: " + json);

    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(json);

    try {
        utx.commit();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicMixedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

This is my web.xml which maps the Servlet:

 <servlet>
  <display-name>BomItemToJSON</display-name>
  <servlet-name>BomItemToJSON</servlet-name>
  <servlet-class>com.xxx.servlets.BomItemToJSON</servlet-class>
 </servlet>

<servlet-mapping>
  <servlet-name>BomItemToJSON</servlet-name>
  <url-pattern>/BomItemToJSON</url-pattern>
 </servlet-mapping>

When I click on the item, I get the alert saying “Forward the url when clicked with id”. But it seems like that the getJSON() function is not called. Why?

  • 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-02T02:30:31+00:00Added an answer on June 2, 2026 at 2:30 am

    A few debugging tips to find whats missing:

    1. Use Firebug for Firefox (I still find the other equivalents less good)
    2. Use console.log(“text”) instead of alerts, they are not as disruptive. Remember to remove them / comment them out as they break in IE etc.
    3. Use the debugger in the script tab in Firebug to check that your code reaches the getJson function in the first place. Also you can debug the callback function.
    4. Use the net tab to see if your /BomItemToJSON url is called and what response is given to the browser.

    Also, I personally like to use the $.ajax function only in jQuery and not their shorthands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to transfer a table from MySQL to MSSQL using the data
I'm trying to transfer some data from Access to SQL Server 2000 (there are
I'm trying to read the POST data from a request with Transfer-Encoding: chunked while
I'm trying to transfer the data from my production DB to my staging DB
Ultimately I'm trying to transfer buffers from one machine to another. The code below
I am trying to export data from database to an excel sheet, using php
I am trying to transfer data from one page to another but some problem
I'm trying to find the best way to transfer data from server -> client
I'm trying to transfer data from a DataSet into an Excel workbook. Unfortunately, I
I'm using the MySql.Data dll from MySql and trying to execute a query to

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.