-1

I have to do a project as exam and I'm getting really troubled with this topic. My project is about a photoblog like Instagram. As in Instagram I want to get values from my DB and posting after the page has been loaded. So I've understood I need help from AJAX but every example I've found is about using PHP and I can't for my projects. Tools I can use are: HTML, CSS, XML, JQuery, AJAX, Servlet/JSP, DOM and JSON. I've found examples in PHP and I've tried to "translate" into Servlet/JSP but it (obviously) didn't work. This is my idea:

    $.ajax({ type: "GET",   
     url: "Jspfile",   
     success : function()
     {
        // Here I would like to use the return value from db that I got by a servlet/jsp file
     }
});

I'm using MySQL aS DB

  • have u tried anything – Tejus Prasad Jan 10 '16 at 15:23
  • *"I've found examples in PHP and I've tried to "translate" into Servlet/JSP but it (obviously) didn't work"* — Why "obviously"? If Java is your server side language then that is exactly what you need to do. – Quentin Jan 10 '16 at 15:29

1 Answers1

-2

You'll have to connect your Java applet to the database, then serialize the data from whatever object type your DB driver uses to JSON.

You then have to render the JSON in your "Jspfile" URL. Then, you just have to parse the JSON in your success / complete function in the jQuery request.

Julien H
  • 63
  • 5
  • It's so simple! ... Now *how* do you do that? – Niet the Dark Absol Jan 10 '16 at 16:36
  • We don't know his DB type so I can't really expand more here. Maybe, point him to the `JSON.parse` function and this other answer to return JSON from JSP : https://stackoverflow.com/questions/9124960/how-to-simply-return-json-from-a-jsp – Julien H Jan 10 '16 at 16:44