Results 1 to 2 of 2

Thread: ContentNegotiatingViewResolver could not find BestView!

  1. #1
    Join Date
    Dec 2011
    Posts
    2

    Question ContentNegotiatingViewResolver could not find BestView!

    Hi there,I'm new in here.. This is my very first post and i hope that someone could help me.

    I'm developing a web app with spring which use ContentNegotiantingViewResolver to delegate the correct response in html or Json.

    If I ask for the json, response is a correct json string. But if i ask for a view which is resolved by the internalResourceViewController (Url:manifestazioni.list), I've got a servletException which complain about
    Code:
     "Could not resolve view with name 'organizzazioni' in servlet with name 'subscriptionmanager'"
    Diving deeper in resolveViewName (in org.springframework.web.servlet.ContentNegotiation ViewResolver) i see that the List<MediaType> requestedMediaTypes contains only [application/octect-stream]. So the next method getBestView could not find any view resolver for the view name.

    I've a page called manifestazioni.jsp inside /WEB-INF/jsp

    Following there are web.xml, subscriptionmanager-servlet.xml a a little part of the controller. I'm using spring-webmvc 3.0.6 inside an appengine app


    the web.xml
    Code:
    <display-name>SubscriptionManager</display-name>
      <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
      </welcome-file-list>
      <servlet>
        <display-name>SubscriptionManager</display-name>
        <servlet-name>subscriptionmanager</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>subscriptionmanager</servlet-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.save</url-pattern>
        <url-pattern>*.list</url-pattern>
        <url-pattern>*.show</url-pattern>
        <url-pattern>*.choose</url-pattern>
        <url-pattern>*.confirm</url-pattern>
      </servlet-mapping>
    the servlet xml
    Code:
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    	  <property name="mediaTypes">
    	    <map>
    	   	  <entry key="json" value="application/json"/>
    	      <entry key="html" value="text/html"/>   
    	    </map>
    
    	  </property>
    	  <property name="viewResolvers" >
    	    <list>
    	     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    	 		 p:prefix="/WEB-INF/jsp/"
    	 		 p:suffix=".jsp" 	 
    	 		 >
    	 		<property name="order" value="0" /> 		
    	 	</bean>
    	    </list>
    	  </property>
    	  <property name="defaultViews">
    	    <list>
    	      <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
    	        
    	      </bean>
    	    </list>
    	  </property>
    	</bean>
    and the controller

    Code:
    @RequestMapping(value="/organizzazioni.list",method=RequestMethod.GET)
    	public ModelAndView listOrganizzazioni() {
    		ModelAndView mav= new ModelAndView();
    		mav.setViewName("organizzazioni");
    		mav.addObject("organizzazioni",service.getAllOrganizzazioni());
    		return mav;
    		
    	}
    
    	@RequestMapping(value="/organizzazioni.list",headers = { "Accept=application/json" })
    	@ResponseBody
    	public List<Organizzazione> listOrganizzazioniAsJson() {
    		return service.getAllOrganizzazioni();
    	}

  2. #2
    Join Date
    Dec 2011
    Posts
    2

    Lightbulb Got it!

    I've got it!

    I've used a funny url mapping schema for the urls in the application. THe contentNegotiationViewResolver tried to set the correct contentType for each extension of the url (.lis,.show,.confirm and so on) which is.. application/octect-stream If i "register" my custom extensions to contentType text/html the view name is resolved correctly!

    So i've changed this in my configuration:

    Code:
             <property name="mediaTypes">
    	    <map>
    	   	  <entry key="json" value="application/json"/>
    	      <entry key="html" value="text/html"/>  
    	      <entry key="save" value="text/html"/>
    	      <entry key="list" value="text/html"/>  
    	      <entry key="show" value="text/html"/> 
    	      <entry key="choose" value="text/html"/> 
    	      <entry key="confirm" value="text/html"/> 
    	    </map>
    	  </property>
    and all work now!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •