zoukankan      html  css  js  c++  java
  • Servlet课程0424(一) 通过实现Servlet接口来开发Servlet

    //这是我的第一个Servlet,使用实现Servlet接口的方式来开发
    
    package com.tsinghua;
    
    import javax.servlet.*;
    import java.io.*;
    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import java.io.IOException;
    
    public class Hello implements Servlet{
        /**
         * Method init
         *
         *
         * @param parm1
         *
         @throws ServletException
         *
         */
         //该函数用于初始化该Servlet(类似于类的构造函数)
         //该函数只会被调用一次(当用户第一次访问该Servlet时被调用)
        public void init(ServletConfig parm1) throws ServletException {
            // TODO: 在这添加你的代码
            System.out.println("init it");
        }
    
        /**
         * Method getServletConfig
         *
         *
         * @return
         *
         */
        public ServletConfig getServletConfig() {
            // TODO: 在这添加你的代码
            return null;
        }
    
        /**
         * Method service
         *
         *
         * @param parm1
         * @param parm2
         *
         @throws ServletException
         @throws IOException
         *
         */
         //这个函数用于处理业务逻辑
         //程序员应当把业务逻辑代码写在这里
         //当用户每访问该Servlet时都会被调用
         //req用于获得客户端(浏览器)的信息
         //res用于向 客户端(浏览器)返回信息
        public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
            // TODO: 在这添加你的代码
            //向控制台打印
            System.out.println("serviece it");
            //从res中得到PrintWriter,向浏览器打印信息
            PrintWriter pw = res.getWriter();
            pw.println("hello World!");
        }
    
        /**
         * Method getServletInfo
         *
         *
         * @return
         *
         */
        public String getServletInfo() {
            // TODO: 在这添加你的代码
            return "";
        }
    
        /**
         * Method destroy
         *
         *
         */
         
         //销毁Servlet实例,释放内存
         //1.reload该Servlet(webApps) //2.关闭tomcat //3.关机
        public void destroy() {
            System.out.println("destroy!");
            // TODO: 在这添加你的代码
            
            
        }
        
        
    }
  • 相关阅读:
    [转]tf.summary() 用法
    PASCAL VOC工具包解读
    [ERROR] 安装完Detectron后出现 cython_nms.so: undefined symbol: PyFPE_jbuf
    用Tensorflow做蝴蝶检测
    双系统,重装ubuntu后无法进入windows
    [Error]NodeDef mentions attr 'identical_element_shapes' not in Op<name=TensorArrayV3;
    [转]调试 smallcorgi/Faster-RCNN_TF 的demo过程遇到的问题
    js交互轮播图
    js取俩个数之间的随机数
    原生js实现触摸滚动轮播图
  • 原文地址:https://www.cnblogs.com/beautiful-code/p/5428081.html
Copyright © 2011-2022 走看看