views:

38

answers:

1

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 database.

A: 

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.

rodrigoap