我一直试图在这个小教程Developing Portlet with Multiple Actions的帮助下调用portlet的方法'signinAction'。 但是当我尝试这样做时,我得到 Portlet暂时不可用错误。我在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>
的Portlet:
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();
}
}
}
请帮助。
答案 0 :(得分:5)
您遇到的一些问题。第一,你的实际问题:
您的portlet似乎继承自javax.portlet.GenericPortlet。这意味着您必须将@ProcessAction(name="signinAction")
添加到方法的签名中。如果你不想要这个注释,你需要从Liferay的MVCPortlet继承,它通过反射找到你想象的方法
您提供的代码的第二个问题:您的jsp包含页面级HTML,例如<html>
,<head>
和<body>
:portlet不得包含此内容,因为它将作为页面的一部分呈现,并且门户网站有责任将这些项目添加到页面中(它们将无论您显示多少个portlet,都只需添加一次)