Soh*_*hil 1 java portlet liferay
我一直在尝试使用这个小教程开发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>
Run Code Online (Sandbox Code Playgroud)
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
你遇到的一些问题.第一,你的实际问题:
看来你的portlet继承自javax.portlet.GenericPortlet.这意味着您必须添加@ProcessAction(name="signinAction")到方法的签名中.如果你不想要这个注释,你需要从Liferay的MVCPortlet继承,它通过反射找到方法,因为你似乎期望它
您提供的代码的第二个问题:您的jsp包含页面级HTML,例如<html>,<head>和<body>:Portlet不得包含此内容,因为它将作为页面的一部分呈现,并且门户网站有责任将这些项目添加到页面中(无论你显示多少个portlet,它们只会被添加一次)
第三:作为一个规则,一个portlet不应该有成员变量 - 事实上,将ThemeDisplay作为一个portlet类成员将导致以后的随机失败:通常只有一个portlet对象处理应用程序获得的所有请求.您必须使ThemeDisplay成为局部变量而不是成员,以避免并发问题和随机用户数据泄漏到其他用户的请求处理中
| 归档时间: |
|
| 查看次数: |
1282 次 |
| 最近记录: |