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

 
 


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

What is a server push method in servlet?

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.