最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java的web.xml中context-param与init-param的区别介绍
时间:2022-06-29 02:52:18 编辑:袖梨 来源:一聚教程网
web.xml中
package test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 5222793251610509039L;
@Override
public void init() throws ServletException {
System.out.println(this.getInitParameter("name"));
}
@Override
protected void service(HttpServletRequest request, HttpServletResponse resposne)
throws ServletException, IOException {
System.out.println(this.getInitParameter("name"));
System.out.println(this.getServletContext().getInitParameter("appversion"));
System.out.println(request.getServletContext().getInitParameter("appversion"));
}
}
上面代码的输出结果是:
yedward
yedward
1.0
1.0
启动一个WEB项目的时候,容器(如:Tomcat)会去配置文件web.xml读两个节点:
ServletContext = ServletContextEvent.getServletContext();
context-param的值 = ServletContext.getInitParameter("context-param的键");
得到这个context-param的值之后,你就可以做一些操作了。注意,这个时候你的WEB项目还没有完全启动完成,这个动作会比所有的Servlet都要早。换句话说,这个时候,对
相关文章
- 蛋仔派对2周年庆前瞻在哪里 06-02
- 江南百景图测试服招募怎么玩 06-02
- 阴阳师小朋友驾到怎么玩 06-02
- 鸣潮舒云秘制凉茶配方怎么获得 06-02
- 猜一猜:古人说的“夏清侯”是以下哪种物品的别称 蚂蚁庄园6月3日答案早知道 06-02
- 以下哪种食物富含胡萝卜素,大量食用可能会皮肤变黄 蚂蚁庄园今日答案6月3日 06-02