ServletConfig与ServletContext详解-ServletConfig实例

package com.hailuo.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Servlet01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        ServletConfig servletConfig = getServletConfig();
        String webSite = servletConfig.getInitParameter("webSite");
        String email = servletConfig.getInitParameter("email");
        PrintWriter writer = response.getWriter();
        writer.println("<h1>"+webSite+"</h1>");
        writer.println("<h1>"+email+"</h1>");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}

访问结果
在这里插入图片描述

上一篇:数据中台高频面试题及参考答案(持续更新)


下一篇:Sentinel链路流控模式失效的解决方法