你自己创建一个jar包,里面有个不固定参数,需要使用者自己配置参数的时候使用;
代码:
ServletConfig config = this.getServletConfig();
String paraName = config.getInitParameter("name");
if (paraName == null) {
PrintWriter out = response.getWriter();
throw new IllegalArgumentException("name这个参数一定要写");
} else {
System.out.println("name....");
}
xml:
</servlet-mapping>
<servlet>
<servlet-name>configTest</servlet-name>
<servlet-class>com.mljqqh.servlet.ServletGet</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>mljqqh</param-value>
</init-param>
</servlet>