I want to set the value of a javascript variable into the jsp request/session via request.getSession().setAttribute(obj, obj), so that I can use it later.
I wrote below piece of code,
function setVal(cache){
var vo = cache;
String voStr = vo;
<% request.getSession().setAttribute("single_"%>+voStr+<%, "true"); %>
}
Here, I called the 'setVal' func, by the onclick event of a button and there's no error showing in the syntax, so I hope the syntax is correct. But while I'm running the jsp, it's causing JasperException/ ServletException in the console.
javax.servlet.ServletException: Unable to compile class for JSP:
An error occurred at line: 46 in the jsp file: /home.jsp
The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String)
Can anyone please suggest, how can I set value in the request.getSession().setAttribute , via a javascript function.