为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我每次运行项目时request都initialize了三次

代码如下

```

public class FirstListener implements ServletRequestListener {

   // Public constructor is required by servlet spec
   public FirstListener() {
   }

@Override
   public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
       System.out.println("request destroyed initParam=" + servletRequestEvent.getServletContext().getAttribute("initParam"));
   }

   @Override
   public void requestInitialized(ServletRequestEvent servletRequestEvent) {
       servletRequestEvent.getServletContext().setAttribute("intiParam","yang");
       System.out.println("request initialized");
   }
}

```

运行结果

```

Connected to server

[2017-12-23 10:44:47,157] Artifact ListenerDemo:war exploded: Artifact is being deployed, please wait...

[2017-12-23 10:44:47,776] Artifact ListenerDemo:war exploded: Artifact is deployed successfully

[2017-12-23 10:44:47,776] Artifact ListenerDemo:war exploded: Deploy took 619 milliseconds

request initialized

request destroyed initParam=null

request initialized

request destroyed initParam=null

request initialized

request destroyed initParam=null

```

正在回答

1 回答

额,代码竟然不显示

我再贴一下

public class FirstListener implements ServletRequestListener {

   // Public constructor is required by servlet spec
   public FirstListener() {
   }
@Override
   public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
       System.out.println("request destroyed initParam=" + servletRequestEvent.getServletContext().getAttribute("initParam"));
   }

   @Override
   public void requestInitialized(ServletRequestEvent servletRequestEvent) {
       servletRequestEvent.getServletContext().setAttribute("intiParam","yang");
       System.out.println("request initialized");
   }
}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我每次运行项目时request都initialize了三次

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信