0

I'm new in the JSP and Servlet word.
I have a Servlet that builds and returns a XML file. Now I want to create a JSP page that performs a request to this servlet in order to obtain the xml and format it in a HTML table.
How do I send a request to my Servlet from my JSP page?

In other words, this is what I'd like to design:

  1. User opens the JSP page with this parameter: artist=Dream Theater
  2. The JSP page sends a request to my Servlet in order to obtain the artist's songs
  3. The Servlet read the artist's songs from a database and returns the list in XML format
  4. The JSP page creates a nice looking HTML table containing the data

Does it make sense? I know, the Servlet could return directly the HTML with the data but I'd like to use XML: in this way I could access the data I need from different contexts (from a mobile application for example).

Oneiros
  • 4,328
  • 6
  • 40
  • 69
  • Where's your concrete question? At what step exactly are you stucking while writing code accordingly? Is it obtaining the request parameter from the current request URL using JavaScript? Please breakdown in smaller steps and ask individual questions. In the meanwhile, all I can say is just 1 word: jQuery. – BalusC Feb 12 '13 at 19:56
  • The question is: How do I send a request to my Servlet from my JSP page? – Oneiros Feb 12 '13 at 20:00
  • 1
    Just use ajax. Or jQuery if you don't want to worry about browser specifics and want to end up with 10 times less code. Now, at what step exactly are you stucking while using ajax? Have you read a basic ajax tutorial? – BalusC Feb 12 '13 at 20:02
  • I think i'll use jQuery, thank you. I'm really new to the web development, sorry for the stupid answer :) – Oneiros Feb 12 '13 at 20:22
  • 1
    It's not a stupid question at all. Also, you can improve this by returning a JSON `String` instead of XML. Check BalusC's answer here: [How to use Servlets and Ajax?](http://stackoverflow.com/a/4113258/1065197) – Luiggi Mendoza Feb 12 '13 at 20:43
  • 1
    As an addition to the above recommendations and considering that you are new to Servlets and JSP, this may be useful to you: [Beginning & Intermediate Servlet & JSP Tutorials](http://courses.coreservlets.com/Course-Materials/csajsp2.html) – informatik01 Feb 12 '13 at 22:54

1 Answers1

0

I solved with JQuery and Ajax:

$.ajax({
    type : "GET",
    url : MyServlet,
    data : {
        artist: myArtist,
    },
    success : function(data) {
        //Data to HTML
    }
});
Oneiros
  • 4,328
  • 6
  • 40
  • 69