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-INF/classes/RequestHeaders.java
Preview
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>
<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>");
}
}
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>");
}
}
How to Run?
> Start Apache Server
> Start localhost and open program folder
> type url '/visit'
> Start Apache Server
> Start localhost and open program folder
> type url '/visit'
0 comments :