Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

spring mvc - what is the difference in org.springframework.web.servlet.ModelAndView vs org.springframework.web.portlet.ModelAndView

Can anybody tell the difference between

org.springframework.web.servlet.ModelAndView

and

org.springframework.web.portlet.ModelAndView

both the ModelAndViews have almost same methods. A significant difference to notice was when I added object to org.springframework.web.portlet.ModelAndView, the object was not able to reach to the view. In the view the added object was null. Do you people know any other significant difference??!! Please add your information here :)

In general the question can also be put as to spot the difference in

org.springframework.web.servlet.*;
org.springframework.web.portlet.*;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well, they are exactly similar, except that *.servlet.* classes are tailored for classical web applications based on servlets, while *.portlet.* one are specially tailored for JSR-168 portlets.

This is a deliberate choice from Spring : As much as possible, the Portlet MVC framework is a mirror image of the Web MVC framework, and also uses the same underlying view abstractions and integration technology.

But a portlet in much different from a servlet. You could find references on the JSR-168 and a nice presentation on What Is a Portlet - O'Reilly Media. Here are some extracts from the latter :

Portlets are web components--like servlets--specifically designed to be aggregated in the context of a composite page. Usually, many portlets are invoked to in the single request of a portal page. Each portlet produces a fragment of markup that is combined with the markup of other portlets, all within the portal page markup.

[Windows for different applications are] developed independently of each other. The developer of the news portlet will create an application and pack it into a .war file. Then the administrator of the portal server will install this .war file on the server and create a page. In the next stage, every user will choose which applications he wants on his page.

For that reason, Spring portlet classes are very different from portlet ones, even when they present same interface. The main way in which portlet workflow differs from servlet workflow is that the request to the portlet can have two distinct phases: the action phase and the render phase. The action phase is executed only once and is where any backend changes or actions occur, such as making changes in a database. The render phase then produces what is displayed to the user each time the display is refreshed.

TL/DR : So *portlet* classes have been specialy designed to present a similar interface to the developper (same as *servlet*) but are quite different under the hood and must not be used in classical (servlet) SpringMVC applications.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...