[英]How to pass data from Java class to a JSP page
I am a newbie in JSP and Dynamic web projects.我是 JSP 和动态 Web 项目的新手。 My project structure is shown as below.
我的项目结构如下所示。 Basically, I am having a variable temperature in my SparkStreaming class which is generated in every 2 seconds and I wish to pass this value to the A.JSP page .
基本上,我的 SparkStreaming 类中有一个可变温度,它每 2 秒生成一次,我希望将此值传递给 A.JSP 页面。 I shall be generating few charts based on the JSP page.
我将根据 JSP 页面生成一些图表。
Simply you can use sessions.只需使用会话即可。
think in java class you have string variable call temperature
.想想在java类中你有字符串变量调用
temperature
。
string temperature = "11.11";
request.removeAttribute("temp");
request.setAttribute("temp", temperature);
in removeAttribute
you clear the session stored value.then you set value to session.在
removeAttribute
您清除会话存储的值。然后将值设置为会话。
In JSP u can access session value like this.在 JSP 中,您可以像这样访问会话值。
request.getAttribute("temp");
您应该有一个 servlet,然后在 jsp 中调用该 servlet 以获取最新的温度值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.