javascript - 如何在 javascript 函数中设置 request.getSession().setAttribute(obj, obj)
问题描述
我想通过request.getSession().setAttribute(obj, obj)将 javascript 变量的值设置到 jsp 请求/会话中,以便以后可以使用它。
我在下面写了一段代码,
function setVal(cache){
var vo = cache;
String voStr = vo;
<% request.getSession().setAttribute("single_"%>+voStr+<%, "true"); %>
}
在这里,我通过按钮的 onclick 事件调用了 ' setVal ' 函数,并且语法中没有显示错误,所以我希望语法是正确的。但是当我运行 jsp 时,它会在控制台中导致JasperException / ServletException 。
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)
任何人都可以建议,我如何通过javascript函数在request.getSession().setAttribute中设置值。
解决方案
推荐阅读
- c# - 使用 c# Interop.domino.dll 使用管理员帐户创建 NotesSession
- reactjs - 如何根据元素的索引在嵌套查询的结果中设置@client 变量
- salesforce-chatter - Salesforce 中 ConnectAPI 的测试类?
- mysql - 如何一次转换mysql列类型和排序规则?
- java - JavaFX并发冻结ui
- python - 在循环中创建和分配变量
- php - PHP/JavaScript 网站中的错误:注意:尝试访问 null 类型值的数组偏移量
- r - 将 tibbles 存储在 tibbles 中
- python - “tensorflow.python.framework.ops.EagerTensor”对象没有“挤压”属性
- javascript - VS Code 更改语法高亮