Liferay 6.1.0中有一个portlet,其中jsp被重定向到另一个带有URL参数的jsp。
http://localhost:8081/web/guest/debitpayment?fishId=1467
我希望使用下面的代码获取fishId
的值,但它为null:
@Override
protected Object formBackingObject(PortletRequest request) throws Exception {
HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
String fishId = httpServletRequest.getParameter("fishId");
//fishId is null
return super.formBackingObject(request);
}
最后,我尝试使用此代码从queryString
获取值,然后返回值。但我想知道为什么从httpServletRequest
获取它是空的。
@Override
protected Object formBackingObject(PortletRequest request) throws Exception {
String fishId = getParameter(request,"fishId");
//fishId is now 1476
return super.formBackingObject(request);
}
public static String getParameter(PortletRequest portletRequest, String paramName) {
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(portletRequest);
HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(httpRequest);
String retval = portletRequest.getParameter(paramName);
if (isNull(retval)) {
retval = httpRequest.getParameter(paramName);
if (isNull(retval)) {
retval = httpServletRequest.getParameter(paramName);
if (isNull(retval)) {
retval = getParameterFromQueryString(httpServletRequest.getQueryString(), paramName);
if (isNull(retval)) {
HttpServletRequest request = httpServletRequest;
try {
while (request != null) {
Method m = httpServletRequest.getClass().getMethod("getRequest", null);
request = (HttpServletRequest) m.invoke(request, null);
retval = request.getParameter(paramName);
if (Utility.isNotNull(retval))
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
return retval;
}
private static String getParameterFromQueryString(String queryString, String paramName) {
String[] paramValues = queryString.split("&");
for (String paramValue : paramValues) {
String[] param = paramValue.split("=");
if (param.length == 2 && param[0].equalsIgnoreCase("currentURL")) {
String url = param[1];
String[] url_splittedWithQuestionMark = url.split("%3F");// ?
// mark
if (url_splittedWithQuestionMark.length == 2) {
String url_params = url_splittedWithQuestionMark[1];
String[] url_paramValues = url_params.split("%26");// & mark
for (String url_paramValue : url_paramValues) {
String[] one_paramValue = url_paramValue.split("%3D");
// =
// mark
if (one_paramValue.length == 2 && one_paramValue[0].equals(paramName))
return one_paramValue[1];
}
}
}
}
return null;
}
答案 0 :(得分:0)
我发现问题的原因和答案。 我在liferay-portlet.xml中为此portlet使用了 render-weight 配置来更改其在页面中加载的优先级。当我删除此配置时,一切正常。