4.从env-entry获取:
马克-to-win:用env-entry存放的参数,本个web应用中的任何servlet,jsp都可以获得。和context-param相比,env-entry存放的参数不止为String类型。下面的comp是component的意思。
例:1.4.1
ServletHello1.java:
package com;
import java.io.IOException;
import java.io.InputStream;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletHello1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Context ctx;
boolean isReady = false;
try {
ctx = new InitialContext();
Boolean b = (Boolean) ctx.lookup("java:comp/env/isReady");
isReady = b.booleanValue();
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("" isReady);
}
}
更多请看:https://blog.csdn.net/qq_44594371/article/details/103157675