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)
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class VisitServlet 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");
}
else
{
out.println("You visited "+i+" times");
}
i++;
}
}
Web.xml file(servlet entry)
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
<servlet-name>VisitServlet</servlet-name>
<servlet-class>VisitServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VisitServlet</servlet-name>
<url-pattern>/servlet/VisitServlet</url-pattern>
</servlet-mapping>
</web-app>
import javax.servlet.*;
import javax.servlet.http.*;
public class VisitServlet 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");
}
else
{
out.println("You visited "+i+" times");
}
i++;
}
}
Web.xml file(servlet entry)
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
<servlet-name>VisitServlet</servlet-name>
<servlet-class>VisitServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VisitServlet</servlet-name>
<url-pattern>/servlet/VisitServlet</url-pattern>
</servlet-mapping>
</web-app>
Awesome blog. Your articles really impressed for me, because of all information so nice and unique. Java Training in Chennai
ReplyDeleteWrite 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)
Deletepython projects for final year students
Deep Learning Projects for Final Year
Useful information.I am actual blessed to read this article.thanks for giving us this advantageous information.I acknowledge this post.and I would like bookmark this post.Thanks
ReplyDeletepython training institute in chennai
python training in Bangalore
python training in pune
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeleteBlueprism training in Pune
Blueprism online training
Blue Prism Training in Pune
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteData Science training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
This is such a great post, and was thinking much the same myself. Another great update.
ReplyDeletejava training in omr | oracle training in chennai
java training in annanagar | java training in chennai
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteangularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training
sheck out java books.gretings from my used bookstore
ReplyDeleteNice Blog. the blog is very Impressive. every concept of this blog is really satisfied the queries for the Learners.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteOracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore | Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune | Oracle Training | Online Course | Certification in coimbatore
Wonderful blog...very easy coding I am easy to learn...Thanks your sharing!!
ReplyDeleteAndroid Training in Chennai | Certification | Mobile App Development Training Online | Android Training in Bangalore | Certification | Mobile App Development Training Online | Android Training in Hyderabad | Certification | Mobile App Development Training Online | Android Training in Coimbatore | Certification | Mobile App Development Training Online | Android Training in Online | Certification | Mobile App Development Training Online
This is good site and nice point of view.
ReplyDeleteDigital Marketing Training in Chennai | Certification | SEO Training Course | Digital Marketing Training in Bangalore | Certification | SEO Training Course | Digital Marketing Training in Hyderabad | Certification | SEO Training Course | Digital Marketing Training in Coimbatore | Certification | SEO Training Course | Digital Marketing Online Training | Certification | SEO Online Training Course
I am a beginner and I have some doubts regarding this post. Can you help out?
ReplyDeleteFrom where we can get to know about url-pattern in this program
ReplyDeleteThis is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.
ReplyDeletebest data science training in hyderabad
This post is so usefull and attracive.keep updating with more information...
ReplyDeleteRPA Course In Mumbai
RPA Course In Ahmedabad
RPA Training In Kochi
RPA Training In Trivandrum
RPA Training In Kolkata
This post is so interactive and informative.keep update more information...
ReplyDeleteAWS Training in Velachery
AWS Training in Chennai
Thanks for sharing this blog with us. Really informative and knowledgeable content to all. Keep up this work in further blogs.
ReplyDeleteData Science Course Training in Hyderabad
Great Blog!!! thanks for sharing this information with us.
ReplyDeleteGoogle Ads Job
Job in Google Ads
360DigiTMG offers the best Data Science Courses on market. Enroll now for a bright future.
ReplyDeletebest data science courses in chennai