[英]Access context param from a class inside lib jar
是否可以从lib中的jar或普通的Java类访问上下文参数?
You didn't mention which framework you are using but assuming you are using HttpServlet
you can use getServletContext
method to retrieve the ServletContext
and then you can retrieve context parameters by getInitParameter(String)
method. 您没有提到正在使用哪个框架,但是假设您正在使用
HttpServlet
,则可以使用getServletContext
方法检索ServletContext
,然后可以通过getInitParameter(String)
方法检索上下文参数。
ServletContext ctx = getServletContext();
String dbDriver = ctx.getInitParameter( "your_parameter_name" );
You can read more about HttpServlet , ServletContext and getServletContext method . 您可以阅读有关HttpServlet , ServletContext和getServletContext方法的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.