开发者

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

开发者 https://www.devze.com 2022-12-18 13:44 出处:网络
Using spring 3.0 MVC: Is it possible to programatically execute a controller\'s action, and return the generated output (the html)?

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

精彩评论

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

关注公众号