实例 1:获取初始化参数
1.web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<servlet>
<description>This is the descri component</description>
<display-name>This is the dis component</display-name>
<servlet-name>GetInitParameterServlet</servlet-name>
<servlet-class>web.servlet.GetInitParameterServlet</servlet-class>
<init-param>
<param-name>repeat</param-name>
<param-value>5</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>GetInitParameterServlet</servlet-name>
<url-pattern>/servlet/GetInitParameterServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2. doGet 方法
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int repeat=Integer.parseInt(getInitParameter("repeat"));
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
评论5
最新资源