求助servlet获取初始化参数的问题
我用的是tomcat7.0,它的web.xml是自动配置的不用手工配置,我现在修改了其配置想设置一个参数在servlet中使用,但不知为什么读过来的参数为null<servlet>
<servlet-name>GetInitParameterServlet</servlet-name>
<servlet-class>GetInitParameterServlet</servlet-class>
<init-param>
<param-name>repeat</param-name>
<param-value>5</param-value>
</init-param>
</servlet>
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
PrintWriter out=response.getWriter();
out.println("<HTML>");
out.println("<head><title>");
out.println("</title></head>");
out.println("<body>");
int n=Integer.parseInt(this.getInitParameter("repeat"));
for(int i=0;i<n;i++)
{
printContent(out);
}
out.println("</body>");
out.println("</HTML>");
out.flush();
out.close();
}
public void printContent(PrintWriter out)
{
out.println("servlet");
}