import java.io.IOException;
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(urlPatterns="/webfragment")
public class SampleWebFragmentServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub
arg1.getOutputStream().print("WebFragment");
}
@Override
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(arg0, arg1);
}
}
上述servlet可以用http://localhost:8080/fragment/webfragment访问。
在servlet3规范中,大量使用了注释。
原文:http://www.javacodegeeks.com/2013/08/servlet-3-0-overview.html