I have tried many ways to use the httponly flag to prevent XSS attack, but all failed.
Common way is to set use HttpOnly=true in context.xml 
For test the result:  in the java code set two test parameters in the cookie and in front jsp file include javascript to alert thedocument.cookie, the two test parameters set in java code are get and show in the alert.  
Java code:
 Cookie cookie = new Cookie("httponlytest","testsss");  
 response.addCookie(cookie); 
 Cookie cookie1 = new Cookie("testhttponly","successfu"); 
 response.addCookie(cookie1); 
javascript in jsp file:
alert("cookie------------"+document.cookie);
- Is there anything i did wrong?
 - If you know how, it would be very helpful.