Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
90
Chapter 3 Handling the Client Request: Form Data
Listing 3.9 BadCodeServlet.java (continued)
    "if (a
    "  doThis();\n" +
    "} else {\n" +
    "  doThat();\n" +
    "}\n";
  public String getCodeFragment() {
    return(codeFragment);
  }
  
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "The Java  if  Statement";
    
    out.println(ServletUtilities.headWithTitle(title) +
                "\n" +
                "

" + title + "

\n" +
                "
\n" +
                getCodeFragment() +
                "
\n" +
                "Note that you must use curly braces\n" +
                "when the  if  or  else  clauses contain\n" +
                "more than one expression.\n" +
                "");
  }
}
Listing 3.10 FilteredCodeServlet.java 
package coreservlets;
/** Subclass of BadCodeServlet that keeps the same doGet method
 *  but filters the code fragment for HTML specific characters.
 *  You should filter strings that are likely to contain
 *  special characters (like program excerpts) or strings
 *  that are derived from user input.
 */
public class FilteredCodeServlet extends BadCodeServlet {
  public String getCodeFragment() {
    return(ServletUtilities.filter(super.getCodeFragment()));
  }
}
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved