开发者

Is it possible to return the output (html) of a particular controller's action?

Using spring 3.0 MVC:

Is it possible to programatically execute a controller's action, and return the generated output (the html)?

I want to take that output and store it in the datab开发者_开发技巧ase.


I think that is possible. Have you ever written a jUnit test for a controller? Mocking the request and the response would be one way of doing it.
Another way is using HttpClient and simulating a browser:

    GetMethod get = new GetMethod("http://httpcomponents.apache.org");
    // execute method and handle any error responses.
    ...
    InputStream in = get.getResponseBodyAsStream();
    // Process the data from the input stream.
    get.releaseConnection();

This code is from this page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜