
Hi this is tanu, This is a code for knowing how many times a servlet has been accessed. but after executing this i am getting only 1 as output for many times of execution. I want to store the counter value once and then want to know how many times it(servlet) has been called. How to store that value and where?
package counter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//In this example we are going to know how we can make a program on counter which will keep track
//how many times the servlet has been accessed.
/**
* Servlet implementation class SimpleCounter
*/
public class SimpleCounter extends HttpServlet {
int counter = 0;
//private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
counter++;
out.println("At present the value of the counter is:" + counter);
// TODO Auto-generated method stub
}
}

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.