前三章
1、servlet name
Internal name 1 foo.Servlet1 Internal name 2 foo.Servlet2 Internal name 1 /Public1 Internal name 2 /Public2
2、P80简单Servlet
package com.example.web;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class BeerSelect extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { response.setContentType(“text/html”); PrintWriter out = response.getWriter(); out.println(“Beer Selection Advice”); String c = request.getParameter(“color”); out.println(“Got beer color “ + c); }}
P89简单dispatch至JSP
package com.example.web;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class BeerSelect extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { response.setContentType(“text/html”); PrintWriter out = response.getWriter(); request.setAttribute(“styles”, result); RequestDispatcher view = request.getRequestDispatcher(“result.jsp”); view.forward(request, response); }}