继承GenericServlet
package com.lee;
import javax.servlet.GenericServlet;
import javax.servlet.*;
import java.io.*;
public class GenericDemo extends GenericServlet{
// 重写Service方法
public void service (ServletRequest req,ServletResponse res){
try{
PrintWriter pw = res.getWriter();
pw.println("Hello world! genneric");
}catch(Exception e){
e.printStackTrace();
}
}
}
XML配置文件:
<servlet>
<servlet-name>genericDemo</servlet-name>
<servlet-class>com.lee.GenericDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>genericDemo</servlet-name>
<url-pattern>/gen</url-pattern>
</servlet-mapping>