Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
378
Chapter 15 Integrating Servlets and JSP
Listing 15.10 ShowPage.java
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example of the include method of RequestDispatcher.
* Given a URI on the same system as this servlet, the
* servlet shows you its raw HTML output.
*/
public class ShowPage extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url = request.getParameter("url");
out.println(ServletUtilities.headWithTitle(url) +
"\n" +
"" + url + "
\n" +
"
"
if ((url == null) || (url.length() == 0)) {
out.println("No URL specified.");
} else {
// Attaching data works only in version 2.2.
String data = request.getParameter("data");
if ((data != null) && (data.length() > 0)) {
url = url + "?" + data;
}
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.include(request, response);
}
out.println("\n" +
"\n" +
"