• 初学Servlet之继承GenericServlet


    package app01a;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.GenericServlet;
    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.annotation.WebInitParam;
    import javax.servlet.annotation.WebServlet;
    /**
     * 如何访问:
     *     http://localhost:端口号(使用tomcat没有修改过的是8080)/项目名/下面WebServlet中的urlPatterns
     *  如果使用的是web.xml配置文件,那么访问路径就变为:
     *  http://localhost:端口号(使用tomcat没有修改过的是8080)/项目名/web.xml中该servlet对应的url-pattern
     * @author Administrator
     *
     */
    @WebServlet( name = "GenericServletDemoServlet",
            urlPatterns = { "/generic" },
            initParams = {
                    @WebInitParam( name = "admin", value = " Harry Taciak"),
                    @WebInitParam( name = "email", value = " admin@example.com")
            })
    public class GenericServletDemoServlet extends GenericServlet{
        private static final long serialVersionUID = 1L;
           
        public GenericServletDemoServlet() {
            
        }

        public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
            ServletConfig servletConfig = getServletConfig();
            String admin = servletConfig.getInitParameter("admin");
            String email = servletConfig.getInitParameter("email");
            response.setContentType("text/html");
            PrintWriter writer = response.getWriter();
            writer.print("<html><head></head><body>" + "Admin:" + admin + "<br/>Email:" + email +
                    "</body></html>");
        }

    }

  • 相关阅读:
    kubernetes集群部署
    centos7通过yum安装mysql,并授权远程连接
    查看mysql主从配置的状态及修正 slave不启动问题
    ios 企业发布
    centos 安装 pip
    前端优化:DNS预解析提升页面速度
    apache mesos 安装
    Oboe 提升web 用户体验以及性能
    webpack 多entry 配置
    webpack es6支持配置
  • 原文地址:https://www.cnblogs.com/wadmwz/p/7521464.html
Copyright © 2020-2023  润新知