<%@ page import="javax.servlet.jsp.PageContext" %> <% PageContext pageContext = (PageContext) request.getAttribute("javax.servlet.jsp.jspPageContext"); pageContext.getResponse().setContentType("text/html"); %>
<%@ page import="javax.servlet.ServletException" %> <%@ page import="java.io.IOException" %> <%@ page import="javax.servlet.jsp.PageContext" %> <% String message = "Hello World!"; try { PageContext pageContext = (PageContext) request.getAttribute("javax.servlet.jsp.jspPageContext"); pageContext.getResponse().getWriter().println(message); } catch (IOException ex) { throw new ServletException("Error writing message to response output stream", ex); } %>In this example, we use getResponse() and getWriter() to write a message to the response output stream. We first retrieve the PageContext object from the request attribute, and then use getResponse() to retrieve the response object. We then use getWriter() to get the output stream and write the message "Hello World!" to it. These examples are using the javax.servlet.jsp package library.