一、环境简介

  项目以前使用的是RCP框架,现想支持web请求,为了减少后台逻辑处理工作量,重用之前的RCP程序代码,通过添加一个新的插件用于处理web请求。具体实现可见http://blog.csdn.net/rongyongfeikai2/article/details/39577237。

二、问题现象

  在前台的一个页面中有两种ajax请求device和plan。页面显示的表格内容是通过plan请求填充,操作需要用到的数据通过定时的device请求来获取。这两个请求的后台处理类为同一个HttpServlet类。在重复刷新的过程中,出现plan请求失败的现象,出现请求失败时device请求也会出现异常,但成功返回。

  关键代码如下:

AbstractServlet类

 1 import javax.servlet.http.HttpServlet;
 2 import javax.servlet.http.HttpServletRequest;
 3 import javax.servlet.http.HttpServletResponse;
 4 
 5 public abstract class AbstractServlet extends HttpServlet {
 6     
 7     /** 请求*/
 8     protected HttpServletRequest request;
 9     
10     /** 响应*/
11     protected HttpServletResponse response;
12     
13     /** 操作名称*/
14     protected String action;
15     
16     /** 请求结果*/
17     protected boolean result;
18     
19     @Override
20     protected void doGet(HttpServletRequest request, HttpServletResponse response){
21         this.request = request;
22         this.response = response;
23         
24         getActionParam();
25         
26         excetue();
27         
28         returnResult();
29         
30     }
31     
32     /**
33      * 获取前端的action字段
34      */
35     protected void getActionParam() {
36         action = request.getParameter("action");    
37     }
38     
39     
40     abstract  public void excetue();
41     
42     abstract protected void returnResult();
43 }
View Code

相关文章:

  • 2021-08-27
  • 2021-12-21
  • 2021-12-21
  • 2022-12-23
  • 2022-01-01
  • 2021-08-25
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2021-05-20
  • 2021-09-17
  • 2021-12-21
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案