2011-04-10
1. HttpServletResponse对象中的getWriter()方法返回一个可以向客户端传送text的PrintWriter对象
2.
/**
* Called by the servlet container to indicate to a servlet that the servlet is being
* placed into service.
* The servlet container calls the init method exactly once after instantiating the
* servlet. The init method must complete successfully before the servlet can receive any
* requests.
* The servlet container cannot place the servlet into service if the init method
* Throws a ServletException Does not return within a time period defined by the Web server
*
* Parameters: config - a ServletConfig object containing the servlet's configuration and
* initialization parameters
*
* Overrides method to
* @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
message = config.getInitParameter("message");
}
这里config所用到的参数值从application的web.xml文件中读取
<servlet>
<servlet-name>ShowMsg</servlet-name>
<servlet-class>mypackage.ShowMessage</servlet-class>
<init-param>
<param-name></param-name>
<param-value>Hey</param-value>
</init-param>
</servlet>