S
sc_wizard29
Hi everyone,
I have a web application which consists of 2 JSP pages. Each page
displays the number of time the page has been accessed. This is
accomplished by using a jsp declaration :
(this sample is taken from the following book : "Servlets and
JavaServer Pages : The J2EE Technology Web Tier")
<%! int pageCount = 0;
void addCount() { pageCount++; }
%>
<html>
<head>
<title>page1.jsp</title>
</head>
<body>
<% addCount(); %>
This page has been visited <%= pageCount %> times.
</body>
</html>
Now, let's say I want to ruse the JSTL tags instead. This will give
something like (not tested) :
<c:set var='pageCount1' scope='application' value='${pageCount1 +1}'/This page has been visited <c
ut var='pageCount1/>' times.
I have 2 questions :
Q#1 : with JSP declarations, the page counter can have the SAME name
on each JSP. But if I use an application scoped counter, the counter
will have to have a DIFFERENT name for each page (ie : pageCounter1
for page1.jsp, pageCounter2 for page2.jsp). Is there a way to use the
same name ?
Q#2 : how do I initialize the value of the application scoped counter
if I use JSTL ? (for example, what if I want the counter to start from
100 ?)
Thanks for helping !
I have a web application which consists of 2 JSP pages. Each page
displays the number of time the page has been accessed. This is
accomplished by using a jsp declaration :
(this sample is taken from the following book : "Servlets and
JavaServer Pages : The J2EE Technology Web Tier")
<%! int pageCount = 0;
void addCount() { pageCount++; }
%>
<html>
<head>
<title>page1.jsp</title>
</head>
<body>
<% addCount(); %>
This page has been visited <%= pageCount %> times.
</body>
</html>
Now, let's say I want to ruse the JSTL tags instead. This will give
something like (not tested) :
<c:set var='pageCount1' scope='application' value='${pageCount1 +1}'/This page has been visited <c
I have 2 questions :
Q#1 : with JSP declarations, the page counter can have the SAME name
on each JSP. But if I use an application scoped counter, the counter
will have to have a DIFFERENT name for each page (ie : pageCounter1
for page1.jsp, pageCounter2 for page2.jsp). Is there a way to use the
same name ?
Q#2 : how do I initialize the value of the application scoped counter
if I use JSTL ? (for example, what if I want the counter to start from
100 ?)
Thanks for helping !