java - 无法使用 <portlet :actionURL> 调用 portlet 的方法

标签 java liferay portlet

在这个小教程的帮助下,我一直在尝试调用 portlet 的方法“signinAction”Developing Portlet with Multiple Actions . 但是当我尝试这样做时,出现了Portlet is temporary unavailable 错误。我在 Tomcat 的服务器控制台中看不到任何内容。此外,当我使用 processAction() 时,我没有收到错误。我不知道出了什么问题。

JSP:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:actionURL var="signinAction" name="signinAction">
</portlet:actionURL>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>


</head>
<body onload="load()" id="body1">
<form action="<%=signinAction.toString() %>" name="signinForm" method="post" onsubmit="return signin(this)">

<center>

<div class="div-upside-down" id="div-style">    

<table  width="95%">
<tr>
    <td colspan="3"><p class="pp"></p>
    </td>
</tr>
<tr>
    <td id="td1">
        <input type="text"  id="email" name="email"  placeholder="Email" />
        <p id="one"></p>
    </td>

    <td id="td2">
        <input type="password"  id="password" name="password"  placeholder="Password" />
        <p id="one"></p>
    </td>

    <td id="td3">
        <input type= "submit" name= "submit" value="Login"/>
        <p id="one"></p>
    </td>
</tr>
</table>
</div>
</center>
</form>
</html>

小门户:

public class HelloWorldPortlet extends GenericPortlet {

ThemeDisplay td;


 public void signinAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException{
       long companyId=10154;
       String email = actionRequest.getParameter("email");
       String password = actionRequest.getParameter("password");

       try
        {
        int authResult = 0;
        long userId = 0;
        Company company = PortalUtil.getCompany(actionRequest);
        Map headerMap = new HashMap();


        Map parameterMap = actionRequest.getParameterMap();



        authResult = UserLocalServiceUtil.authenticateByEmailAddress(company.getCompanyId(), email, password,headerMap, parameterMap, null);
        userId = UserLocalServiceUtil.getUserIdByEmailAddress(company.getCompanyId(), email);
        User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email);
        String screenId = user.getScreenName();
        td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);  

        MethodKey key = new MethodKey("com.liferay.portlet.login.util.LoginUtil", "login", HttpServletRequest.class, HttpServletResponse.class, String.class, String.class, boolean.class, String.class);
        PortalClassInvoker.invoke(false, key, new Object[] { PortalUtil.getHttpServletRequest(actionRequest), PortalUtil.getHttpServletResponse(actionResponse),screenId, password, true, CompanyConstants.AUTH_TYPE_SN});
        actionResponse.sendRedirect(td.getPathMain());

        }
        catch (Exception e)
        {
        e.printStackTrace();
        }
        }
}

请帮助。

最佳答案

您遇到的一些问题。第一个,您的实际问题:

您的 portlet 似乎是从 javax.portlet.GenericPortlet 继承的。这意味着您必须添加 @ProcessAction(name="signinAction")到你的方法的签名。如果你不想要这个注解,你需要继承 Liferay 的 MVCPortlet,它通过反射找到你似乎期望的方法

您提供的代码的第二个问题:您的 jsp 包含页面级 HTML,例如<html> , <head><body> : portlet 不得包含此内容,因为它将作为页面的一部分呈现,门户负责将这些项目添加到页面(无论您显示多少个 portlet,它们都只会添加一次)

第三:根据经验,一个 portlet 不应该有成员变量——事实上,将 ThemeDisplay 作为一个 portlet 类成员会导致以后随机失败:通常只有一个 portlet 对象处理所有请求应用程序获取。您必须使 ThemeDisplay 成为局部变量而不是成员,以避免并发问题和随机用户数据泄漏到其他用户的请求处理中

关于java - 无法使用 <portlet :actionURL> 调用 portlet 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16129546/

相关文章:

liferay - 如何在 portlet 的操作阶段创建 RenderURL?

java - While 循环不工作

java - 替换捕获组

tomcat web.xml cors.allowOrigin 删除条目

database - 使用 Liferay 向多对多表添加列

java - Liferay Unresolved 需求

java - Liferay Portlet 检查 View 状态

java - 在 Hadoop 中拆分Reducer 输出

java - 为什么我的 libgdx scene2d 元素变黑了?

spring-mvc - Liferay上Portlet开发方法的建议