<body>
<h1>第一个servlet小例子</h1>
<a href="servlet/HelloServlet">get方式请求HelloServlet</a><br>
<form action="servlet/HelloServlet" method="post">
<input type="submit" value="用post方式提交HelloServlet" />
</form>
</body>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("处理doGet请求");
PrintWriter out=response.getWriter();
out.println("HelloServlet");
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("处理doPost请求");
PrintWriter out=response.getWriter();
out.println("HelloServlet from post");
}
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>servlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/HelloServlet</url-pattern>
</servlet-mapping>