简体   繁体   English

序列化并存储Controller对象

[英]Serialize and store an Controller object

Does the object contains all the state of pages,desktop, (like a snapshot) What does an controller object actually store. 对象是否包含页面,桌面的所有状态(如快照)?控制器对象实际存储什么。

Is there any way to store the complete data and components on an page into an object. 有什么方法可以将页面上的完整数据和组件存储到对象中。 I want to retrieve same page state. 我想检索相同的页面状态。

This shall clear problem: I want to store complete state of particular portion of web application, and then when I reload the page I want to set the view of the portion that I have saved earlier. 这将清除问题:我想存储Web应用程序特定部分的完整状态,然后在重新加载页面时设置我之前保存的部分的视图。

You can do it if you intercept (or wrap) the servlet output stream. 如果拦截(或包装)servlet输出流,则可以执行此操作。 You can store content returned by your application per request URL, so you will be able to retrieve the state of the application byte-by-byte. 您可以按请求URL存储应用程序返回的内容,因此可以逐字节检索应用程序的状态。

EDIT. 编辑。

Here how you can implement this. 在这里,您可以如何实现它。 Controller is a servlet that implements doGet() and/or doPost . 控制器是实现doGet()和/或doPost的servlet。

Here is how the signature of all such methods look like: 这是所有这些方法的签名的样子:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

The typical pattern of code looks like: 典型的代码模式如下:

// do somthing and get data.
resp.getOuputStream().write(somthing);

You can write your own output stream (or writer) that extends OutputStream and wraps 2 palyload streams: servlet stream and file stream. 您可以编写自己的输出流(或编写器),以扩展OutputStream并包装2个有效载荷流:servlet流和文件流。 It overrides its write method like the following: 它会覆盖其write方法,如下所示:

public abstract void write(int b) throws IOException {
    fileOut.write(b);
    servletOut.write(b);
}

Now each byte is written both to the web client and to file. 现在,每个字节都写入Web客户端和文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM