如何利用注解创建Servlet3.0的web项目
1、在servlet3.0中,servlet、filter,listener不需要配置在web.xml文件中,可以直接通过注解的方式来实现。
首先新建一个支持servlet3的web项目。

2、在servlet3中,我们可以不需要生成web.xml文件。

3、接下来我们发送一个servlet请求,新建一个页面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<a href="hello">hello</a>
</body>
</html>

4、新建一个Servlet,接收来自页面的请求。
package com.gwolf.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("hello ...");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req,resp);
}
}

5、在servlet3.0以前,servlet是需要在web.xml进行一系列的配置,在servlet3中只需要使用一个注解@WebServlet。

6、在tomcat中部署web应用,查看应用的访问情况。
