views:

1364

answers:

2

Hello all:

I have this piece of code:

$("#faq").click(function () {         
    var url = $.get("faq", { pagina: "page" });
    alert(url);
});

On "faq" responds to a Servlet that sets an attribute on the request

....
request.setAttribute("pageFAQ", pageFAQ);
....

After the get jqeury prints [object XmlHttpRequest].

I would like to access to the attribute set in the Servlet but I don't know how to do it.

Any idea?

Kind regards

Massimo UGues

+1  A: 

I'm not sure that a servlet request attribute is shared with the client.

You can get hold of the response text in jQuery like so:

$("#faq").click(function () {                   
  $.get(
    "faq", 
    { pagina: "page" },
    function(data) {    // callback function, executed on GET success
      alert(data);
    }
  );
});

All you need to do is let your servlet return some text.

Tomalak
A: 

setAttribute() Method sets the value that one can retrieve inside the server but not at client side. We use it to set and get the values in servlet communication. You can not access any information thru this method that is outside the server i.e. client program.

We use req.getParameter(paramname) to access client attrubutes.