如何在自定义servlet中获取Liferay会话?

发布于 2024-12-15 06:51:41 字数 857 浏览 1 评论 0原文

我在 Liferay 中编写了自定义 servlet,并想知道哪个用户页面调用它并了解其他参数,例如主题。但请求的属性和会话字段都是空的。

如何使自定义 servlet 像 portlet 一样接收请求?

谢谢

​我不想使用此解决方案 https://www.everit.biz/web/guest/blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp?_33_redirect=/web/guest/blog

手动读取cookie。我想做 Liferay 那样的事情,即使用它的 API。是否可以?

更新 1.

我在一次 WAR 中有一个 portlet 和一个 servlet。我可以从 portlet JSP 中知道我是谁(登录用户),如下所示:

HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);

themeDisplay.getUser()

现在我想从 servlet 中执行相同的操作。是否可以?

我正在自动部署的 eclips 中工作。

I wrote custom servlet in Liferay and want to know which user page calls it and know other parameters like theme. But the request's attributes and session fields are all nulls.

How to make custom servlet to receive request as if portlet does?

Thanks

P.S. I don't want to use this solution https://www.everit.biz/web/guest/blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp?_33_redirect=/web/guest/blog

which reads cookies manually. I want to do such as Liferay does, i.e. by using it's API. Is it possible?

Update 1.

I have a portlet and a servlet in one WAR. I can know who am I (logged in user) from within portlet JSP like this:

HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);

themeDisplay.getUser()

Now I want to do the same from a servlet. Is it possible?

I am working in eclips which deploys automatically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽蝶幻影 2024-12-22 06:51:41

您要么必须模仿 Liferay 在 portlet 请求处理中所做的事情(不推荐),要么将您的 servlet 代码放入 portlet 中 - 这可以是 portlet 的“资源处理” - 在这里您可以完全访问 http 请求并且可以自己完成有关流中传输的数据类型的所有操作。

我宁愿推荐这个,因为它会更容易升级。从逻辑角度来看,Portlet 资源处理程序与 servlet 非常相似。可能还有其他(更明智的)选择,但这就是我针对此类问题想到的。

You either have to mimic what Liferay does in the portlet request handling (not recommended) or, alternatively, put your servlet code into a portlet - this can be the "resource handling" of a portlet - here you get full access to the http request and can do everything yourself with regards to data types transmitted in the stream.

I'd rather recommend this as it will be significantly easier to upgrade. Portlet Resource Handler are very similar to servlets from a logical point of view. There might be other (more advisable) options, but this is what comes to my mind for this type of problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文