Saturday, 21 May 2022

Write a SERVLET program which counts how many times a user has visited a web page. If user is visiting the page for the first time, display a welcome message. If the user is revisiting the page, display the number of times visited. (Use Cookie)

 DOWNLOAD  Slip6Q2



import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Created by : Amar Ghugare
* created on : 21-05-2022 18:56
* Purpose of class : Write a SERVLET program
* which counts how many times a user has visited a web
* page. If user is visiting the page for the first time,
* display a welcome message. If the
* user is revisiting the page, display the number
* of times visited. (Use Cookie)
*/
public class Slip6Q2 extends HttpServlet{
static int i=1;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String k=String.valueOf(i);
Cookie c=new Cookie("visit",k);
response.addCookie(c);
int j=Integer.parseInt(c.getValue());
if(j==1) {
out.println("Welcome to web page ");
}
else {
out.println("You are visited at "+i+" times");
}
i++;
}
}

No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...