@WebServlet
(name =
"MyFirstServlet"
, urlPatterns = {
"/MyFirstServlet"
})
public
class
MyFirstServlet
extends
HttpServlet {
private
static
final
long
serialVersionUID = -1915463532411657451L;
@Override
protected
void
doGet(HttpServletRequest request,
HttpServletResponse response)
throws
ServletException, IOException
{
//Do some work
}
@Override
protected
void
doPost(HttpServletRequest request,
HttpServletResponse response)
throws
ServletException, IOException {
//Do some other work
}
}
所有的Servlet必须是要么继承了 javax.servlet.GenericServlet 的普通Servlet,要么是继承了 javax.servlet.http.HttpServlet 的HTTP Servlet。
RequestDispatcher.forward()转发请求到另一个Servlet
使用HttpServletResponse.sendRedirect()重定向请求到另一个Servlet