掲示板

how to share Session variable between Hook and Servlet ?

6年前 に jerry wang によって更新されました。

how to share Session variable between Hook and Servlet ?

New Member 投稿: 3 参加年月日: 17/04/17 最新の投稿
hi all ,I will add verification code to login page, so i crearted new theme .
i create portlet,used servlet to generate verification code and set verification code values to session ,
servlet code is :
public class CheckCodeServlet extends HttpServlet {
HttpSession session = request.getSession();
.... generate image
session.setAttribute("LIFERAY_SHARED_check_code", new String(rands));
}

theme code is
<form action="login1" method="post">
<input type="text" name="_58_login" Placeholder="Username" required>
<input type="password" name="_58_password" Placeholder="Password" required>
<img src="/checkCode-portlet/testServlet"/>
</form>

------------------------------------
i create hook will be check verification code, but can't get the session value
public class InsecureAutoLogin implements AutoLogin {
@Override
public String[] login(HttpServletRequest request,
HttpServletResponse response) throws AutoLoginException {
String itcode = request.getParameter("_58_login");
String password = request.getParameter("_58_password");
HttpSession session = request.getSession(false);
System.out.println(session.getId());
String saveCode = (String)session.getAttribute("LIFERAY_SHARED_check_code");
System.out.println(saveCode);
return null;
}
}
hook portal.properties
auto.login.hooks=com.liferay.signin.portlet.InsecureAutoLogin
session.shared.attributes=org.apache.struts.action.LOCALE,COMPANY_,USER_,LIFERAY_SHARED_

please help,thx
6年前 に jerry wang によって更新されました。

RE: how to share Session variable between Hook and Servlet ?

New Member 投稿: 3 参加年月日: 17/04/17 最新の投稿
hello?
6年前 に Harsh Kanakhara によって更新されました。

RE: how to share Session variable between Hook and Servlet ?

Junior Member 投稿: 74 参加年月日: 17/04/06 最新の投稿
Try passing true in the method

HttpSession session = request.getSession(false);


Also I recommend you not to use custom portlet. Try using login jsp hook to achieve your requirement.

Regards,
Harsh Kanakhara.