Example 2-9. Saying Hello using a JSP declaration
Example 2-9. Saying Hello using a JSP declaration
Hello, <%= getName(request) %>
The background servlet created to generate this page might look like the servlet shown in Example 2-10. Example 2-10. The workhorse servlet for a JSP page with a declaration import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class _hello3_xjsp extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) Example 2-10. The workhorse servlet for a JSP page with a declaration (continued) throws ServletException, IOException { response.setContentType( text/html ); PrintWriter out = response.getWriter(); BufferedReader in = request.getReader(); out.printIn( ); out.printIn(); out.printIn( Hello, + getName(request)); out.printIn(
); out.printIn( ); } private static final String DEFAULT_NAME = World ; private String getName(HttpServletRequest req) { String name = req.getParameter( name ); if (name == null) return DEFAULT_NAME; else return name; }Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services