Listing 6 - Listing 6.1 WrongDestination.java package...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Listing 6.1 WrongDestination.java package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Servlet that sends IE users to the Netscape home page and * Netscape (and all other) users to the Microsoft home page. */ public class WrongDestination extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userAgent = request.getHeader("User-Agent"); if ((userAgent != null) && (userAgent.indexOf("MSIE") != -1)) { response.sendRedirect("http://home.netscape.com"); } else { response.sendRedirect("http://www.microsoft.com"); } } } Listing 6.2 SearchEngines.java package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; /** Servlet that takes a search string and a search * engine name, sending the query to * that search engine. Illustrates manipulating * the response status code. It sends a 302 response * (via sendRedirect) if it gets a known search engine, * and sends a 404 response (via sendError) otherwise. */ public class SearchEngines extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String searchString = request.getParameter("searchString"); if ((searchString == null) || (searchString.length() == 0)) { reportProblem(response, "Missing search string"); return; } // The URLEncoder changes spaces to "+" signs and other // non-alphanumeric characters to "%XY", where XY is...
View Full Document

This note was uploaded on 11/14/2011 for the course MATH 401 taught by Professor H.ayad during the Spring '11 term at Cairo University.

Page1 / 6

Listing 6 - Listing 6.1 WrongDestination.java package...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online