留言板

JSP Portlet <jsp:include> problem

Shing Lam,修改在14 年前。

JSP Portlet <jsp:include> problem

New Member 发布: 1 加入日期: 10-3-4 最近的帖子
We are developing jsp portlets to be deployed in liferay portal. In one of the jsp, we use the jsp:include tag to include another jsp, passing the parameter using the jsp:param tag.

---- test1.jsp ----

<jsp:include page="test2.jsp>
<jsp:param name="a" value="#{var1}">
</jsp>


Found that using liferay-tomcat6-5.2.3 bundle, the non-ascii value of parameter got garbled.

Found that jsp compiler generated java code, the parameters were first urlencoded before passing to the included jsp, using the character Encoding passed by request.getCharacterEncoding().

org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("a", request.getCharacterEncoding())

In a jsp portlet, the portlet is wrapped from com.liferay.portal.PortletServletRequest.

in this class,
...
public String getCharacterEncoding() {
if (_lifecycle.equals(PortletRequest.ACTION_PHASE) ||
_lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

return _request.getCharacterEncoding();
}
else {
return null;
}
}
...

Only in ACTION_PHASE or RESOURCE_PHASE, the character encoding of the underlying request is got, otherwise, null is returned.

so the
org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode would encoding the string using the default encoding i.e. iso-8859-1, which would garbled the data.

I would like to know why the getCharacterEncoding() should return null?

Regards,

Shing