zoukankan      html  css  js  c++  java
  • 初学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>");
        }

    }

  • 相关阅读:
    Leetcode Substring with Concatenation of All Words
    Leetcode Divide Two Integers
    Leetcode Edit Distance
    Leetcode Longest Palindromic Substring
    Leetcode Longest Substring Without Repeating Characters
    Leetcode 4Sum
    Leetcode 3Sum Closest
    Leetcode 3Sum
    Leetcode Candy
    Leetcode jump Game II
  • 原文地址:https://www.cnblogs.com/wadmwz/p/7521464.html
Copyright © 2011-2022 走看看