1

I am trying to load a new jquery tab with HTML from the server:

$("#tab"+username).load("/lod1/ProfileServlet",{user:"username"},function(){
            //fill in template with user's info
            console.log("it worked");
 });

servlet:

    System.out.println("USERNAME HERE");
    RequestDispatcher req = request.getRequestDispatcher("/WEB-INF/profileTemplate.html");
    req.forward(request, response);

In the browser I see the confirmation 'it worked' so it seems that the request was successful. But on the server I don't see the output "USERNAME HERE" and "#tabusername" is not populated with the html requested(which I can confirm is in the right place):

<!DOCTYPE html>

<div>
    <h1>USERS PROFILE AND THEME</h1>
</div>
Kresimir
  • 777
  • 5
  • 20
MadMax
  • 605
  • 1
  • 6
  • 19
  • Is "/lod1/ProfileServlet" a GET or a POST? As data is provided, you are calling with a POST. – jordiburgos Dec 01 '18 at 20:55
  • it's in doGet(), I moved the html page out of webinf and changed the url of .load to '/lod1/profileTemplate.html' removed the data and it worked. But say I wanted to return the page via servlet ? Why didn't it work like they say here: – MadMax Dec 01 '18 at 20:58
  • https://stackoverflow.com/questions/17036130/how-to-return-an-html-document-from-java-servlet – MadMax Dec 01 '18 at 20:58
  • ah: "Request Method The POST method is used if data is provided as an object; otherwise, GET is assumed." – MadMax Dec 01 '18 at 21:00
  • thanks @jordiburgos – MadMax Dec 01 '18 at 21:00

1 Answers1

3

As your servlet is listening for a GET, you can't pass the data to .load() as the second data parameter.

Use this to call the servlet with a GET:

$("#tab"+username).load("/lod1/ProfileServlet?user="+username, function() {
    //fill in template with user's info
    console.log("it worked");
});
jordiburgos
  • 5,964
  • 4
  • 46
  • 80