美文网首页
Servlet API:Servlet接口

Servlet API:Servlet接口

作者: Jianbaozi | 来源:发表于2020-11-20 14:37 被阅读0次
    image.png

    提示已存在检查web.xml中是否已经存在

        <servlet>
            <description>
            </description>
            <display-name>HelloServlet</display-name>
            <servlet-name>HelloServlet</servlet-name>
            <servlet-class>com.baozi.HelloServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>HelloServlet</servlet-name>
            <url-pattern>/HelloServlet</url-pattern>
        </servlet-mapping>
    
    package com.baozi;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    
    /**
     * Servlet implementation class HelloServlet
     */
    public class HelloServlet implements Servlet{
    
        /**
         * Default constructor. 
         */
        public HelloServlet() {
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see Servlet#init(ServletConfig)
         */
        public void init(ServletConfig config) throws ServletException {
            // TODO Auto-generated method stub
        }
    
        /**
         * @see Servlet#destroy()
         */
        public void destroy() {
            // TODO Auto-generated method stub
        }
    
        /**
         * @see Servlet#getServletConfig()
         */
        public ServletConfig getServletConfig() {
            // TODO Auto-generated method stub
            return null;
        }
    
        /**
         * @see Servlet#getServletInfo()
         */
        public String getServletInfo() {
            // TODO Auto-generated method stub
            return null; 
        }
    
        /**
         * @see Servlet#service(ServletRequest request, ServletResponse response)
         */
        public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
            PrintWriter pwt=response.getWriter();
            pwt.println("Hello Servlet!");
            pwt.close();
        }
    
    }
    
    
    image.png

    相关文章

      网友评论

          本文标题:Servlet API:Servlet接口

          本文链接:https://www.haomeiwen.com/subject/exbdiktx.html