Additional research on liferay portal (III): Solution to the session loss problem of IFRAME Portlet

Source: Internet
Author: User
Tags form post
Liferay provides a very simple method of Web application integration and single point of login: IFRAME Portlet. IFRAME Portlet can be used to easily include an existing web application, and form post or get can be used for user login.

There is no problem with the liferay mechanism, and the implementation is also very clever. However, for many web application systems, after using the liferay IFRAME Portlet form method to implement login, although the login can be successful, however, on the displayed new page, the user information is lost, or more accurately, the session is lost. In fact, this phenomenon has little to do with liferay, but is determined by the application itself. In fact, the IFRAME mode of all portal context may occur. Because many web application systems, after performing the login operation, habitually choose the redirect operation, which forces the display address in the browser to change to the transferred address. In fact, this is a very correct practice. Under normal circumstances, there will be no problems, and it can also prevent problems caused by PAGE refresh. However, in the IFRAME Portlet of liferay, a redirect operation such as a web application causes the session to become a new one after being transferred to a new page, this results in the loss of login user information stored in the original session. Follow up and perform the following tests (liferay and webapp are in different JVM environments ):
Application Location Session ID
(Liferay) Before performing form post D03e1b828395ef5bcb1063a8290bd254
(App_a) Login operations 397bb3656e2a12a96ce3f16e0a89c607
(App_a) New Page after login 58a1054c6ede4a7d6cfa2fcdbb3e0736
It can be seen from the above that, after redirect, the new page of the Web application generates a new sessionid There are two ways to solve this problem. The two methods depend on the Web application incorporated by liferay Portlet. Method 1: After a login operation, the Redirect method is not used, but the dispatcher method. Method 2: After the login operation, the Redirect method is still used, but the current JSESSIONID is assigned to the new page. Dispatcher method:
Servletcontext SC = getservletcontext ();
Requestdispatcher RD = NULL;
RD = SC. getrequestdispatcher ("/index. jsp ");
Rd. Forward (request, response );
Redirect mode (to keep the same session ):
Response. sendredirect ("index. jsp; JSESSIONID = describb3656e2a12a96ce3f16e0a89c607")
In one case, it doesn't matter whether the Redirect method is used. This means that liferay and webapp are in the same JVM environment.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.