获取GWT Web应用程序服务器端的刷新计数

时间:2022-04-12 15:45:51

I am working on converting the functionality of some JSP pages to GWT. I noticed that javax.servlet.http.HttpServletRequest request is an implied object in JSP, and one can obtain the client's refresh count by calling request.getParameter("refreshCount"). I noticed that one can also access this request object in GWT in the service implementation class (extends RemoteServiceServlet) for the client making an RPC call to this service class by calling getThreadLocalRequest(). However, I noticed that the request object has no parameters. How may I possibly get the refresh count of the calling client (through HttpServletRequest or otherwise)?

我正在努力将一些JSP页面的功能转换为GWT。我注意到javax.servlet.http.HttpServletRequest请求是JSP中的隐含对象,可以通过调用request.getParameter(“refreshCount”)来获取客户端的刷新计数。我注意到,也可以在服务实现类(扩展RemoteServiceServlet)中的GWT中访问此请求对象,以便客户端通过调用getThreadLocalRequest()对此服务类进行RPC调用。但是,我注意到请求对象没有参数。我怎么可能得到调用客户端的刷新计数(通过HttpServletRequest或其他)?

1 个解决方案

#1


I don't think getParameter("refreshCount") is an automatic function of servlets. It looks like it is just getting the value of a refreshCount parameter in your query string (URL). Most likely, some other part of your code is setting that value.

我不认为getParameter(“refreshCount”)是servlet的自动功能。看起来它只是在查询字符串(URL)中获取refreshCount参数的值。最有可能的是,代码的其他部分正在设置该值。

Even if it is being tracked automatically by the Servlet class, that would require maintaining session state for that client. GWT RPC calls don't have any built in session functionality. So if you want to do this, you have two options:

即使Servlet类正在自动跟踪它,也需要维护该客户端的会话状态。 GWT RPC调用没有任何内置会话功能。所以如果你想这样做,你有两个选择:

  • You can maintain a "refresh count" variable in the client, and pass it to your RPC method as a parameter.
  • 您可以在客户端中维护“刷新计数”变量,并将其作为参数传递给RPC方法。

  • You can pass some kind of session ID into each of your RPC method calls, and track the refresh count on the server side. This might require storing the session in a database, or in some global memory structure.
  • 您可以将某种会话ID传递到每个RPC方法调用中,并跟踪服务器端的刷新计数。这可能需要将会话存储在数据库中,或存储在某些全局内存结构中。

#1


I don't think getParameter("refreshCount") is an automatic function of servlets. It looks like it is just getting the value of a refreshCount parameter in your query string (URL). Most likely, some other part of your code is setting that value.

我不认为getParameter(“refreshCount”)是servlet的自动功能。看起来它只是在查询字符串(URL)中获取refreshCount参数的值。最有可能的是,代码的其他部分正在设置该值。

Even if it is being tracked automatically by the Servlet class, that would require maintaining session state for that client. GWT RPC calls don't have any built in session functionality. So if you want to do this, you have two options:

即使Servlet类正在自动跟踪它,也需要维护该客户端的会话状态。 GWT RPC调用没有任何内置会话功能。所以如果你想这样做,你有两个选择:

  • You can maintain a "refresh count" variable in the client, and pass it to your RPC method as a parameter.
  • 您可以在客户端中维护“刷新计数”变量,并将其作为参数传递给RPC方法。

  • You can pass some kind of session ID into each of your RPC method calls, and track the refresh count on the server side. This might require storing the session in a database, or in some global memory structure.
  • 您可以将某种会话ID传递到每个RPC方法调用中,并跟踪服务器端的刷新计数。这可能需要将会话存储在数据库中,或存储在某些全局内存结构中。