2010-07-06 55 views
1

我想使用DispatcherPortlet類使Spring MVC 3.0.3 portlet具有JSON支持。所以,我在spring上下文文件中添加了以下配置。錯誤:'ContentNegotiatingViewResolver'Spring 3.0.3 MVC Portlet + JSON

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 

text/html的

沒有這個,如果我使用'InternalResourceViewResolver',那麼它運行良好,我可以使用portlet。但是在定義這個bean的時候,我在tomcat啓動時遇到了以下錯誤。

我搜索了一下,找到一個鏈接,聲明這個帶有JSON的bean只能在最新的spring vesion中使用servlet。請檢查鏈接。

http://jira.springframework.org/browse/SPR-7344(JSON問題Portlet的...)

http://jira.springframework.org/browse/SPR-6932?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel#issue-tabs

也請檢查下面粘貼的錯誤。幫助我... 謝謝。

:ERROR:

java.lang.IllegalArgumentException: Object of class [org.springframework.web.portlet.context.PortletRequestAttributes] must be an instance of class org.springframework.web.context.request.ServletRequestAttributes

,請查看日誌

Caused by: java.lang.IllegalArgumentException: Object of class [org.springframework.web.portlet.context.PortletRequestAttributes] must be an instance of class org.springframework.web.context.request.ServletRequestAttributes 
at org.springframework.util.Assert.isInstanceOf(Assert.java:337) 
at org.springframework.util.Assert.isInstanceOf(Assert.java:319) 
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:363) 
at org.springframework.web.portlet.DispatcherPortlet.resolveViewName(DispatcherPortlet.java:1110) 
at org.springframework.web.portlet.DispatcherPortlet.render(DispatcherPortlet.java:1052) 
at org.springframework.web.portlet.DispatcherPortlet.doRenderService(DispatcherPortlet.java:761) 
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:522) 
+0

您好,請您粘貼處理方法?我似乎無法使其工作http://stackoverflow.com/q/4498266/306488。我真的很感激,如果你幫我出來 – lisak 2010-12-21 13:05:52

+0

我讀過這兩個線程:http://forum.springsource.org/showthread.php?t=83673 ... http://forum.springsource.org/showthread .php?t = 97005,但仍不清楚應該如何完成。尤其是響應部分,如何在春季處理程序 – lisak 2010-12-21 13:23:08

回答

1

ContentNegotiatingViewResolver不會與門戶,只有servlet的工作。作爲一般規則,Spring中的許多servlet API類都有一個等價的portlet,例如,

  • org.springframework.web。 servlet .HandlerAdapter
  • org.springframework.web。 門戶 .HandlerAdapter

你必須確保你使用正確的 - 該servlet和Portlet API是完全不兼容。

但是,從Spring 2.5開始,portlet框架被忽略了(可能是因爲它很少使用),並且servlet MVC API的新部分沒有包含在portlet MVC API中。如果你想做你想做的事情,你將不得不自己做很多事情。您可能可以複製ContentNegotiatingViewResolver和相關類的一些代碼。

+0

中響應該請求,謝謝,我發現了bug的jira鏈接,但我不確定。現在我認爲它更好,我創建一個返回JSONObject字符串的servlet,並從JSP中調用它... atleast工作正常:) 有什麼建議嗎? – Parth 2010-07-06 08:04:44

+1

我已經使用單獨的JSON servlet。並從JSP直接調用它...它的返回完美的json:D – Parth 2010-07-06 10:28:59

+1

這裏是鏈接,請投票:https://jira.springsource.org/browse/SPR-7344 – lisak 2010-12-21 14:16:46

0

看看這個。現在應該工作



<!-- View Resolver --> 
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/test/testJSp/" /> 
    <property name="suffix" value=".jsp" /> 
     <property name="order" value="2" /> 
</bean> 
+0

這個問題是關於portlet,而不是servlets – 2013-06-26 12:32:55