Thursday, 9 March 2017

Develop Pragramme for Visite Page Count with use of ServletConfig Interface.

*File Name:

      1)Web.xml:This file is Welcome File.
      2)Servlet14.java :Configure Page Count.


*Web.xml 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>servlet14</servlet-class>

<init-param>
<param-name>counter</param-name>
<param-value>0</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>


</web-app> 

*servvlet14.Java


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Queue
 */
public class servlet14 extends HttpServlet {
    int c;
    
    public void init()
    {
        ServletConfig s=getServletConfig();
        c=Integer.parseInt(s.getInitParameter("counter"));
    }
    
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException
    {
        c++;
         PrintWriter p=res.getWriter();
         p.print("Page you have count"+c);
         
    }
}


Output




Thanks 
Happy Coding ;)
                       


No comments:

Post a Comment