用init-param如何从web.xml中获得参数?


1.用init-param获取:

例:1.1.1

ServletHello1.java:

package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletHello1 extends HttpServlet {undefined
    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {undefined
        String salary = getInitParameter("zhangsan");
        System.out.println("salary is "+salary);
    }
}

 

在web.xml中加入:

 


   
        ServletHello1
        com.ServletHello1
            
                 zhangsan
                 1000
            

   

   
        ServletHello1

更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44594371/article/details/103157414