本文共 1256 字,大约阅读时间需要 4 分钟。
ServletDemo7.java:data XXXXX data1 YYYYY data2 ZZZZZ
package cn.edu;import java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;//获取Web应用的初始化参数public class ServletDemo7 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //单个输出全局初始化参数 String num=this.getServletContext().getInitParameter("data"); System.out.println(num); //输出多个全局初始化参数 Enumeration e = this.getServletContext().getInitParameterNames(); while(e.hasMoreElements()){ String name=(String)e.nextElement(); String value1=this.getServletConfig().getInitParameter(name); System.out.println(name+" = "+value1); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); }}结果: data=XXXXXX data1=YYYYYY data2=ZZZZZZ
转载地址:http://wlwzo.baihongyu.com/