Servlet----------通过 GenericServlet 开发Servlet

通过继承GenericServlet抽象类。只需要重写service()方法即可。(这个知识点了解即可)

 package cn.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; public class MyGenericServlet extends GenericServlet{ @Override
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException {
resp.setCharacterEncoding("GBK");
resp.getWriter().println("中文!");
resp.getWriter().print("hello,我继承了GenericServlet"); }
}

XML部署:

<servlet>
<servlet-name>mygenericservlet</servlet-name>
<servlet-class>cn.servlet.MyGenericServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mygenericservlet</servlet-name>
<url-pattern>/servlet/MyGenericServlet</url-pattern>
</servlet-mapping>

Servlet----------通过 GenericServlet 开发Servlet

上一篇:学习C++模板,初体验


下一篇:我的IT开源之路