Announcement Announcement Module
Collapse
No announcement yet.
writing to response directly in controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
    Error 500: OutputStream already obtained
    InternalResourceViewResolver is configured like this:
    Code:
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass">
    			<value>org.springframework.web.servlet.view.JstlView</value>
    		</property>
    		<property name="prefix">
    			<value>/WEB-INF/jsp/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    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.
    Code:
    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;;
            ...
            out.flush&#40;&#41;;
        &#125;
    &#125;
    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.

    Comment


    • #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

      Comment

      Working...
      X