Saturday 22 June 2013

14. Write a Servlet which displays a message and also displays how many times the message has been displayed (how many times the page has been visited).

WTAD Practical - 14
Write a Servlet which displays a message and also displays how many times the
message has been displayed (how many times the page has been visited).
WEB-INF/web.xml


<web-app>
<servlet>
<servlet-name>s14</servlet-name>
<servlet-class>VisitCount</servlet-class>
</servlet>
<!-- Servlet Mapping -->
<servlet-mapping>
<servlet-name>s14</servlet-name>
<url-pattern>/visit</url-pattern>
</servlet-mapping>
</web-app>


WEB-INF/classes/RequestHeaders.java


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

public class VisitCount extends HttpServlet
{
private int count = 0;
public void doGet( HttpServletRequest request,HttpServletResponse response ) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<HTML>" + 
"<HEAD><TITLE>WTAD.practical-14 @iAmLearningHere</TITLE></HEAD>" +
"<body bgcolor=YellowGreen>");

out.println("Welcome! You have visited iAmLearningHere <b>" + ++count + " </b> times...<br>");
out.println("Keep visiting <b>iamlearninghere.blogspot.in</b> ");

out.println("</table></body></HTML>");

}
}

Preview


How to Run?
> Start Apache Server
> Start localhost and open program folder
> type url '/visit'

For all WTAD programs wtad-pra cticals.html
To get all programs in your inbox.Enter your email

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT