1. 程式人生 > >如何用ServletConfig從init-param獲取引數?

如何用ServletConfig從init-param獲取引數?

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();

詳情請見:http://www.mark-to-win.com/index.html?content=Jsp/jspUrl.html&chapter=Jsp/jsp2_web.html#GetParamWithServletConfiginitparam