您的当前位置:首页Servlet开发之继承GenericServlet

Servlet开发之继承GenericServlet

2024-12-13 来源:哗拓教育

继承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>

显示全文