Announcement Announcement Module
No announcement yet.
writing to response directly in controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • writing to response directly in controller

    It is my understanding, that you can write directly to the response in Controller. I do that to stream a word document from a server.
    The Controller returns null.

    The problem is that I am using InternalResourceViewResolver and it looks like the servlet tries to forward to a jsp and I get
    Error 500: OutputStream already obtained
    InternalResourceViewResolver is configured like this:
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass">
    		<property name="prefix">
    		<property name="suffix">
    Am I doing something wrong?

  • #2
    You can use multiple view resolvers. Add in the one that allows you to specify the class to use for the view. ResourceBundleViewResolver or something like that is the name of it. You may need to specify the property that gives the order of which view resolver is called first.

    Then create a class that implements View; e.g.
    public class
    WordView implements View &#123;
        public void
        render&#40;...&#41; throws Exception &#123;
            response.setContentType&#40;"whatever's right for a word doc"&#41;;
            ServletOutputStream out = response.getOutputStream&#40;&#41;;
    And specify WordView as the view in the resource bundle view config file.

    Note: I've never done this; I'm just guessing from eyeballing the Spring in Action book's section on generating a jpeg file.


    • #3
      Thank you for your promt reply.

      Actually the problem was that intercetors were adding to the model thus the null value was not null anymore. I changed my interceptors and now everything works fine but I will probably change to View anyways