import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class NameThePirate extends HttpServlet { private String escapeValue(String value) { if(value == null) { value = ""; } int indexOfQuote = value.indexOf("'"); String result = ""; while(indexOfQuote > -1) { result = result + value.substring(0, indexOfQuote) + "'"; value = value.substring(indexOfQuote + 1); indexOfQuote = value.indexOf("'"); } if(value.length() > 0) { result = result + value; } return(result); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String pirateName = request.getParameter("piratename"); if(pirateName == null) { pirateName = "Bob"; } //pirateName = escapeValue(pirateName); out.println(""); out.println(""); out.println(""); out.println("Hello World!"); out.println(""); out.println(""); out.println("

Give the Pirate a name

"); out.println(""); out.println("
"); out.println("Yo Ho Ho and a Bottle Of Rum! Hello, My name is " + pirateName); out.println("

"); out.print("

"); out.println("New Pirate Name"); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println(""); out.println(""); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }