zoukankan      html  css  js  c++  java
  • servlet_3

    package com.atguigu.servlet;

    import java.io.IOException;

    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;

    public class BServlet implements Servlet {
    private ServletConfig config;

    //@Override
    public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
    /*
    * ServletContext
    * 代表整个web应用,每个web应用都有他唯一对应的ServletCentext对象,该对象在项目启动时创建,在项目销毁时卸载
    * 获取:通过ServletConfig获取
    * 功能:1,获得整个WEB应用的初始化参数
    * 2,可以获取到资源的真实路径
    * 虚拟路径:http://localhost:8888/9_14_servlet/BServlet
    * 真实路径:资源在硬盘中的地址
    *
    *
    */





    this.config=config;
    }

    //@Override
    public ServletConfig getServletConfig() {
    // TODO Auto-generated method stub
    return this.config;
    }

    //@Override
    public void service(ServletRequest req, ServletResponse res)
    throws ServletException, IOException {
    //获取全局的初始化参数
    ServletContext context = this.getServletConfig().getServletContext();
    String url = context.getInitParameter("url");
    System.out.println("url="+url);
    //获取index.html的真实地址
    //主要用于做上传和下载
    String realPath=context.getRealPath("/index.html");
    System.out.println("realPath");


    // TODO Auto-generated method stub

    }

    //@Override
    public String getServletInfo() {
    // TODO Auto-generated method stub
    return null;
    }

    //@Override
    public void destroy() {
    // TODO Auto-generated method stub

    }

    }

  • 相关阅读:
    面向连接的网络应用程序--服务器端
    使用完整读写函数的网络应用程序
    套接字编程基础
    网络编程基础
    传输控制协议TCP
    UDP协议
    电子词典
    strtok()函数、fseek()函数、fwrite()函数、fread()函数的使用
    指针与数组
    软件推荐----RDO(Remote Desktop Organizer)
  • 原文地址:https://www.cnblogs.com/fanzhengzheng/p/7572128.html
Copyright © 2011-2022 走看看