Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript函数中设置request.getSession().setAttribute(obj,obj)_Javascript_Scriptlet - Fatal编程技术网

如何在javascript函数中设置request.getSession().setAttribute(obj,obj)

如何在javascript函数中设置request.getSession().setAttribute(obj,obj),javascript,scriptlet,Javascript,Scriptlet,我想通过request.getSession().setAttribute(obj,obj)将javascript变量的值设置到jsp请求/会话中,以便以后使用它 我在下面写了一段代码 function setVal(cache){ var vo = cache; String voStr = vo; <% request.getSession().setAttribute("single_"%>+voStr+<%, "t

我想通过request.getSession().setAttribute(obj,obj)将javascript变量的值设置到jsp请求/会话中,以便以后使用它

我在下面写了一段代码

function setVal(cache){
    var vo = cache;
    String voStr = vo;
    <% request.getSession().setAttribute("single_"%>+voStr+<%,  "true"); %>
}

任何人都可以建议,我如何通过javascript函数在请求.getSession().setAttribute中设置值。

您在这里尝试的操作没有任何意义。JavaScript在浏览器中运行。Java在服务器上运行。不能在JavaScript函数中运行Java代码。您必须找到另一种在页面和服务器之间通信的方法。我想在setAttribute()中设置js变量的值。这样我以后才能拿到。我明白你想做什么。但你试图这样做的方式是不合逻辑的。这就像当你的朋友在这个国家的另一边时,你试图把一些东西交给他们。JavaScript代码和Java代码在完全不同的地方运行,因此您不能像在这里尝试的那样将值从一个传递到另一个。我很困惑,如何做到这一点。这里的场景是,应用程序使用一个
table.tag
文件,其目的是在运行时通过填充数据库中的值在jsp页面中构造表。该文件只有标记,我想在加载这个table.tag文件时指定一些计算值。但我不能这样做,因为它不支持javascript onload事件。因此,我考虑通过
request.getSession().setAttribute()
分配该值。但我还是做不到。你能告诉我怎么解决这个问题吗。
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)