tomcat7中的servlet3的使用

在tomcat7中,文件结构完全可以没有web.xml了,而servlet可以通过注解来进行配置.下面就是一个简单的例子.同时eclipse3.6也支持servlet3.0的自动声明.而且servlet3.0采用了异步处理,性能明显得到了提升.
package com.phl.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/SReport")
public class SReport extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public SReport() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		out.write("hello servlet3.0");
	}

}

你可能感兴趣的:(java,Web,xml,servlet)