Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to modify the value of context parameter in Servlet

$
0
0
I have this code with me, I want to implement Page Visit Count. I have declared one context param value in web.xml file with param-name:pageVisitCount, but my code is not functioning. Where am I doing wrong.....if this code is not modifying my context parameter value, then how can I achieve it...?

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class VisitCount extends HttpServlet
	{	
	 public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
		{
			response.setContentType("text/html") ;
			PrintWriter out = response.getWriter() ;
			
			String pageVisitCount = getServletContext().getInitParameter("pageVisitCount") ;
			
			int x = Integer.parseInt(pageVisitCount) ;
			
			x = x+1;
			
			boolean bol = getServletContext().setInitParameter("pageVisitCount",""+x) ;
			
			out.println("Page Visit Count : "+getServletContext().getInitParameter("pageVisitCount") + " "+bol) ;
		}
	}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>