2.用ServletConfig从init-param获取:
就单纯获取init-param而言,上一种和这一种方法一样。不过ServletConfig还有很多其他的功能。见例子。
例:1.2.1
ServletHello1.java:
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletHello1 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletConfig c = getServletConfig();
System.out.println(c.getServletName()+c.getInitParameter("zhangsan"));
}
}
更多请看:https://blog.csdn.net/qq_44591615/article/details/109275414
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。