public
void include(ServletRequest request, ServletResponse response) throws
ServletException, IOException
Includes
the content of a resource (servlet, JSP page, HTML file) in the
response. The included servlet cannot change the response status code
or set headers; any attempt to make a change is ignored.
hello.html
<!DOCTYPE html> <html> <head> <title>Hiiiii</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1>You are going to include me in the response </h1> </body> </html>
import java.io.IOException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @WebServlet(urlPatterns = {"/RequestProcess"}) public class RequestProcess extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ RequestDispatcher dispatch = req.getRequestDispatcher("hello.html"); dispatch.include(req, res); } }
Output
No comments:
Post a Comment