They can easily be undone, so when

They can easily be undone, so when users riot against your tyranny of removing their freedom, you can quickly reverse the change and appease the masses. They handle dynamically created content, so you can trust that your restrictions are maintained, your special tags are replaced, and your dynamically converted PostScript images are properly displayed, even in the output of a servlet (or a CGI script). They handle the content of the future, so you don’t have to run your script every time new content is added. Creating a Servlet Chain Our first servlet chain example removes tags from HTML pages. If you’re not familiar with the tag, be thankful. It is a tag recognized by many browsers in which any text between the and tags becomes a flashing distraction. Sure, it’s a useful feature when used sparingly. The problem is that many page authors use it far too often. It has become the joke of HTML. Example 2-5 shows a servlet that can be used in a servlet chain to remove the tag from all of our server’s static HTML pages, all its dynamically created HTML pages, and all the pages added to it in the future. This servlet introduces the getReader()and getContentType()methods. Example 2-5. A servlet that removes the tag from HTML pages import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Deblink extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String contentType = req.getContentType(); // get the incoming type if (contentType == null) return; // nothing incoming, nothing to do res.setContentType(contentType); // set outgoing type to be incoming type PrintWriter out = res.getWriter(); BufferedReader in = req.getReader(); String line = null; while ((line = in.readLine()) != null) { line = replace (line, , ); line = replace (line, , ); out.printin(line); } } public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doGet(req, res); } private String replace(String line, String oldString, String newString) { int index = 0; while ((index = line.indexOf(oldString, index)) >= 0) { // Replace the old string with the new string (inefficiently)

Note: If you are looking for good and affordable webspace to host and run your servlet application check Sandzak servlet hosting services

Comments are closed.