Jquery how to get attribute from HttpServletRequest
I have this piece of code:
$("#faq").click(function () {
var url = $.get("faq", { pagina: "page" });
alert(url);
});
The "faq" is answered by Servlet, which sets the attribute on request
....
request.setAttribute("pageFAQ", pageFAQ);
....
After get jQuery prints [XmlHttpRequest object].
I would like to access an attribute set on the Servlet, but I don't know how.
source to share
I'm not sure if the servlet request attribute is shared by the client.
You can get 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 have to do is let your servlet return some text.
source to share
setAttribute () Method sets a value that can be retrieved internally on the server, but not on the client side. We use it to set and get values ββin servlet communications. You cannot access any information through this method that is outside the server, that is, the client program.
We are using req.getParameter (paramname) to access client attrubutes.