Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Liferay门户不将对象从流程阶段发送到jsp_Java_Jsp_Request_Liferay_Getattribute - Fatal编程技术网

Java Liferay门户不将对象从流程阶段发送到jsp

Java Liferay门户不将对象从流程阶段发送到jsp,java,jsp,request,liferay,getattribute,Java,Jsp,Request,Liferay,Getattribute,我是liferay的新手,现在我正在用liferay食谱学习liferay。我在将对象从porlet发送到jsp页面时遇到问题 这是我的porlet,。在LibraryPortlet.java中,我有一个函数: public void searchBooks(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { String s

我是liferay的新手,现在我正在用liferay食谱学习liferay。我在将对象从porlet发送到jsp页面时遇到问题 这是我的porlet,。在LibraryPortlet.java中,我有一个函数:

public void searchBooks(ActionRequest actionRequest,
        ActionResponse actionResponse) throws IOException, PortletException {

    String searchTerm = ParamUtil.getString(actionRequest, "searchTerm");

    if (Validator.isNotNull(searchTerm)) {
        try {
            List<LMSBook> lmsBooks = LMSBookLocalServiceUtil
                    .searchBooks(searchTerm);

            actionRequest.setAttribute("SEARCH_RESULT", lmsBooks);
            actionRequest.setAttribute("test", "sentence to test");
            actionResponse.setRenderParameter("jspPage",
                    LibraryConstants.PAGE_LIST);

        } catch (SystemException e) {
            e.printStackTrace();
        }
    }
}
在list.jsp中,booksTemp为null,因为liferay无法将我的对象从LibraryPortlet.java发送到jsp,我尝试将字符串语句发送到test,但在控制台中,它显示test:null


任何人都有同样的问题,你能帮我吗

您必须首先使用正确的请求来设置属性。问题在于,在LibraryPortlet中,您使用的是PortletRequest类型,而JSP中的对象是HttpServletRequest

对于您的情况,在LibraryPortlet.java中,执行以下操作:

HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

request.setAttribute("SEARCH_RESULT", lmsBooks);

这也适用于您正在设置的任何其他属性。

不要像liferay那样声明无法将我的对象从LibraryPortlet.java发送到jsp。请检查您的条件验证器。isNotNullsearchTerm并检查控件是否进入内部。我不明白为什么不声明,你能为我解释一下吗。Validator.isNotNullsearchTerm返回true,这意味着执行了try catch块,只是对象没有发送到jsp file.LibraryConstants.PAGE\u LIST请粘贴thisLibraryConstants.PAGE\u LIST=/html/library/LIST.jsp的值。它只是一个常量值。问题是代码在我的合作伙伴项目中运行良好,但在我的项目中,它是错误的,我不知道为什么。我们是一起学的,我不知道这取决于。。。。
HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

request.setAttribute("SEARCH_RESULT", lmsBooks);