在servlet中配置初始化参数
实验步骤:
1)在servlet中配置初始化参数:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>TestServlet.HelloServlet</servlet-class>
<!-- 给一个servlet配置一个初始的参数 -->
<init-param>
<param-name>charset</param-name>
<param-value>gbk</param-value>
</init-param>
</servlet>
2)在代码中使用如下语句得到参数的值
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
String mycharset= getInitParameter("charset");
response.setCharacterEncoding(mycharset);
PrintWriter out = response.getWriter();
}