问题描述
我有两个按钮,一个叫做Previous,另一个叫做Next。当他们被点击时,他们重新加载它们定义的JSP页面。他们也应该增加或减少一个变量。
< form name =inputaction =MyPage.jsp method =post>
< html>
< input type =submitvalue =Previousonclick =<%hitsCount--;%>>
< / html>
< html>
< input type =submitvalue =Nextonclick =<%hitsCount ++;%>>
< / html>
我遇到的问题是我无法弄清楚如何以这样的方式定义变量如果hitsCount为0,并且我点击下一步按钮,页面应该重新加载,并且它的值不会被重置。 hitsCount应该加1。下一次我点击下一步按钮时,页面重新加载和hitsCount应该包含值为2.
您可以使用会话存储来保存客户端中的值。这是一个,您可以在其中查看会话存储的工作方式。
I have two buttons, one called "Previous" the other is called "Next". When they are clicked, they reload the JSP page in which they are defined. They are also supposed to either increment or decrement a variable.
<form name="input" action="MyPage.jsp" method="post">
<html>
<input type="submit" value="Previous" onclick="<% hitsCount--; %>">
</html>
<html>
<input type="submit" value="Next" onclick="<% hitsCount++; %>">
</html>
The problem I am having is that I cannot figure out how to define the variable in such a way that it is not reset each time the page loads.
For example if "hitsCount" is 0, and I click the "Next" button the page should reload and the value of "hitsCount" should be incremented by one. The next time I hit the "Next" button, the page reloads and "hitsCount" should contain a value of 2.
you can use session storage for keep the values in the client side
Here is a link where you can see how session storage works.
这篇关于如何创建在页面重新加载时不重置的JSP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!