Eclipse中HttpServlet类找不到

Eclipse中使用的HttpServlet类之所以识别不到的原因是没有导入Servlet-api.jar包

这个包在所安装在的tomcat的lib文件中,只需要导入即可解决。

public void init(ServletConfig _config) throws ServletException {

        super.init(config);

// 获取config对象

ServletConfig config = _config;

System.out.println(config);

 

// 它常用的功能有三个。

// 1.获取Servletweb.xml文件中配置的Servlet名称(也就是servlet-name的值<servlet-name>ConfigServlet</servlet-name>)。

String servlet_name = config.getServletName();

System.out.println("servlet-name ==>> " + servlet_name);

 

// 2.获取Servlet初始化信息。(web.xml文件中<Servlet>标签中 <init-param>的初始化信息 )

String param_value = config.getInitParameter("username");

System.out.println("username 的值:" + param_value);

 

// 3.获取ServletContext域对象

// ServletContext它是一个域对象,并且一个Web工程对应一个ServletContext

ServletContext context = config.getServletContext();

System.out.println(context);

}

猜你喜欢

转载自www.cnblogs.com/dododo70/p/12382752.html