这就是我正在尝试做的事情:
我正在尝试从 liferay 主题调用 servlet/ Controller (无论我能先做什么)。
这就是我所做的: 我创建了一个名为 XController 的 Controller ,然后生成一个 url 来调用它:
#set ($embeddedPortletURL = $portletURLFactory.create($request, "workspace_WAR_xportlet", $page.plid, "RESOURCE_PHASE"))
<input id="workspaceSearchUrl" value="${embeddedPortletURL}" type="hidden">
然后对于 ajax 调用,我使用 $("#workspaceSearchUrl").val() + "&p_p_mode=view&p_p_resource_id=doSomething"
作为网址。
我能够毫无问题地调用 portlet,但是每当我调用 portletRequest.getRemoteUser() 时,我都会得到“2203”的 userId,而不是登录的用户。
所以...我到底做错了什么?为什么 getRemoteUser 方法返回一个数字?
编辑: 需要明确的是,对其他 Controller 的其他 ajax 调用会返回有效的用户 ID(文本)。
我还尝试调用 servlet,但是调用 getRemoteUser 返回 null。我猜这意味着 servlet 不与门户共享 session ?
最佳答案
如果可以的话,尝试使用
User currentUser = PortalUtil.getUser(portletRequest);
long userId = currentUser.getUserId();
关于java - 调用 request.getRemoteUser 时获取数字 userId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19024768/