import java.io.IOException;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
//扩展GenericServlet实现Servlet程序
public class Demo12 extends GenericServlet {
public void service(
ServletRequest request,
ServletResponse response)
throws ServletException, IOException {
//服务端通知浏览器以指定的编码方式来显示中文
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write("欢迎学习JavaServlet程序");
}
}
配置web.xml
<servlet>
<servlet-name>Demo4</servlet-name>
<servlet-class>cn.web.http.Demo4</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Demo4</servlet-name>
<url-pattern>/Demo4</url-pattern>
</servlet-mapping>
扩展GenericServlet实现Servlet程序 学习笔记
原文地址:http://blog.51cto.com/357712148/2104361