Returning HTML from ResourceRequests with SpringWebMVC
If you have a use case where it is helpful to present a link that returns HTML content from the portlet, such as a gateway SSO portlet that needs to return HTML page content that initiates a Single-Sign-On to another system, one approach is to use a Resource URL that returns the HTML page from a JSP file. The SpringWebMVC View Resolver must set the alwaysInclude property to true to include the JSP file rather than forward to it. With the default behavior, the JSP page will never be compiled or included.
Spring applicationContext configuration
<!--
| View resolvers, JSP resolution
| To allow a resource URL to return an HTML page, must set alwaysInclude=true. Otherwise Spring
| will attempt to do a forward rather than an include and the page won't render.
-->
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="10" p:cache="true" p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:alwaysInclude="true"/> Then in your JSP and controller do normal resource URL handling.
Display JSP file
<portlet:resourceURL var="emailLink" id="displayEmailLaunchPage"/>
<a href="${emailLink}" target="_blank"><spring:message code="sso.email.link"/></a>Controller
@Controller
@RequestMapping("VIEW")
public final class EmailPortletController {
...
@RenderMapping()
public String doView(RenderRequest request, Model model) {
String jspName = request.getParameter("nextJspPage");
if (jspName == null) {
final PortletPreferences prefs = request.getPreferences();
jspName = prefs.getValue(JSP_NAME_PREFERENCE, DEFAULT_JSP_NAME);
}
return jspName;
}
@ResourceMapping(value = "displayEmailLaunchPage")
public String displayEmailLaunchPage() {
return LAUNCH_JSP;
}
...
} Target JSP-HTML page
<html>
<head>
...
</html> Additional References
Having problems with these instructions?
Please send us feedback at uportal-user@lists.ja-sig.org