Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJWCD
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Web Component Certification (OCEJWCD)
HttpSession doubt
Ashok Pradhan
Ranch Hand
Posts: 180
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Numbers of previous attemptes
does not change after second attempt to call the
servlet
.Please suggest what is the problem with my servlet:--
Here is my servlet code :-
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import java.text.*; public class SessionTracking extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter pw = response.getWriter(); HttpSession session=request.getSession(); int ctr=1; String msg=null; if(session.isNew()){ msg = "Hello new User"; } else{ msg="Wel come back"; ctr++; } pw.println("<h1 align=center>"); pw.println(msg+"<br>"); pw.println("Session ID="+session.getId()+"<br>"); pw.println("Session Creation Time="+DateFormat.getInstance().format(new Date(session.getCreationTime()))); pw.println("<br>Time of Last Access="+DateFormat.getInstance().format(new Date(session.getLastAccessedTime()))); pw.println("<br>Number of previous Attempt="+ctr); } }
Jonathan Elkharrat
Ranch Hand
Posts: 170
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
your ctr variable is local, it's scope is the method only.
try to store it in the session:
if (session.isNew()) {
msg = "Hello new User";
session.setAttribute("counter",ctr);
}
else {
msg = "Welcome back";
ctr=(Integer)session.getAttribute("counter")+1;
session.setAttribute("counter",ctr);
}
SCJP 5, SCWCD 5, SCBCD 5
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Code Review - ChatServlet
date
HttpSessionBindingListener
jsp/tomcat undefined type error
Regarding HttpSession
More...