How to get a Liferay session in a custom servlet?

I wrote my own servlet in Liferay and I want to know which user page calls it and knows other parameters, such as the theme. But request attributes and session fields are zeros.

How to get a custom servlet to receive a request like a portlet?

thanks

PS I do not 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 this, e.g. Liferay, i.e. Using its API. Is it possible?

Update 1.

I have a portlet and servlet in one WAR. I know who I am (registered user) from the JSP portlet, 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 the servlet. Is it possible?

I work in eclipses that automatically deploy.

+6
source share
1 answer

You either need to imitate what Liferay does in processing portlet requests (not recommended), or, alternatively, put your servlet code in the portlet - this may be the "resource handling" of the portlet - here you get full access to the http request and can do everything yourself in relation to the types of data transmitted in the stream.

I would recommend this, as it will be much easier to update. The Portlet resource handler is very similar to servlets in a logical sense. There may be other (more appropriate) options, but this is what comes to my mind for this type of problem.

+3
source

Source: https://habr.com/ru/post/901299/


All Articles