Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Servlet-Interview-Questions What is Server push in servlet?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shabeer
What is Server push in servlet?
1 Answer(s)      6 years and 9 months ago
Posted in : Servlet Interview Questions


What is a server push method in servlet?


Advertisement
View Answers

February 27, 2008 at 3:49 PM


Server push means that a server pushes content to the browser client and in server-push, the server cannot actually initiate a TCP connection to the client.

Server-push Example and Code
ServerPushExam.java

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

public class ServerPushExam extends HttpServlet {
int accesses = 0;

public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

accesses++;
out.print("Number of times this servlet has been accessed:" + accesses);
}
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">; -->



<web-app>
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>ServerPushExam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/ServerPushExam</url-pattern>

</servlet-mapping>
</web-app>


Resources: -
http://www.roseindia.net/software-tutorials/detail/13368



Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com