public
boolean isCommitted()
isCommitted
method
returns a boolean value indicating whether any response bytes
have been returned to the client.
Main.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <form method="get" action="/servlet/GetData"> <input type="submit" value ="Get Data"> </form> </body> </html>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <servlet> <servlet-name>GetData</servlet-name> <servlet-class>GetData</servlet-class> </servlet> <servlet-mapping> <servlet-name>GetData</servlet-name> <url-pattern>/GetData</url-pattern> </servlet-mapping> </web-app>
GetData.java
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class GetData extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ try(PrintWriter out = res.getWriter()){ res.setContentType("text/html"); String str1 = "<html><head><title>Buffer size</title>" + "<body><h1>"; System.out.println("Is Response Committed " + res.isCommitted()); out.println(str1); out.println("Is Response Committed " + res.isCommitted() +"<br />"); res.flushBuffer(); out.println("Is Response Committed " + res.isCommitted()); out.println("</h1></body></html>"); } } }
No comments:
Post a Comment