page counter in JSP & JSTL

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:eek: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 !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSTL attempt in JSP 5
JSTL Question 10
JSTL 0
JSP (w JSTL) passing arrays from one included page to another 0
JSP works, JSTL doesn't 4
Help with my responsive home page 2
JSTL 1
problem in jsp/jstl 2

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top