O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Search Results Page

Now that we have our form, we need to provide an action for it. First, we'll create the SearchResults servlet, which echoes back our entry, as in Listing 7.11.

Listing 7.11. SearchResults.java: Creating the Servlet
 0:import java.io.*; 1:import javax.servlet.*; 2:import javax.servlet.http.*; 3: 4:public class SearchResults extends HttpServlet { 5: 6: public void doGet(HttpServletRequest request, 7: HttpServletResponse response) 8: throws IOException, ServletException 9: { 10: response.setContentType("text/html"); 11: PrintWriter out = response.getWriter(); 12: 13: String key = request.getParameter("key"); 14: out.print("Results for keyword: " + key + "<br /><br />"); 15: 16: } 17: 18: 19: public void doPost(HttpServletRequest ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required