숫자와 버튼이있는 곳에 JSP 프로그램을 만들려고합니다. 버튼을 클릭하면 위의 숫자가 증가합니다. 이 프로그램에서 세션을 사용해야합니다.JSP 간단한 프로그램
이것은 내가했던 코드는 다음과 같습니다
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Welcome </title>
</head>
<body>
<%
// check if there already is a "Counter" attrib in session
AddCount addCount = null;
int test = 0;
String s;
try {
s = session.getAttribute("Counter").toString();
} catch (NullPointerException e){
s = null;
}
if (s == null){
// if Counter doesn't exist create a new one
addCount = new AddCount();
session.setAttribute("Counter", addCount);
} else {
// else if it already exists, increment it
addCount = (AddCount) session.getAttribute("Counter");
test = addCount.getCounter();
addCount.setCounter(test);
addCount.addCounter(); // increment counter
session.setAttribute("Counter", addCount);
}
%>
<%! public void displayNum(){ %>
<p> Count: <%= test %> </p>
<%! } %>
<input TYPE="button" ONCLICK="displayNum()" value="Add 1" />
</body>
</html>
결과는 내가 프로그램을 실행할 때마다이 숫자의 증가가 .. 그러나 내가 증가시킬 수를 원하는 .. 이런 일이하고 싶지 않은 것입니다 버튼을 클릭하면 :/내가 뭘 잘못하고 있니?
도움 주셔서 감사합니다. 대단히 감사하겠습니다!
JSP와 HTML/JS에 관해 어디에서 배웠습니까? JS와 JS를 혼동하고있다. (oldschool 90의 HTML 스타일과 대문자로 된 속성 이름을 사용하고 oldschool 00의 JSP * scriptlets *를 사용한다.) 주제에 대한 적절한 자습서를 읽고 계십니까? 이 웹 사이트의 – BalusC
: http://www.jsptut.com/Sessions.jsp :/더 좋은 것이 있습니까? 나는 정말로 혼란 스럽다. JSP인지 JS인지는 모르겠다. :/어디서부터 시작해야할지 모르겠다./ – Bernice
여기서 JS를 사용하고 있는가? :/ – Bernice