Javaweb Summary of the transfer of two project sessions and page transfer between different projects

Source: Internet
Author: User

The business system and a cms system in the project need to share sessions. This is a summary of my work. I don't know if it is SSO. What I want is to implement functions.
Project A and Project B are two different projects under tomcat, Project A is the business system, and Project B is the cms system, the goal is to log on to A and jump to B to get the session information of.
Because A cannot directly jump to B's page in struts. xml of a after login, A adds A jsp page in A (to jump to B's page in this page) to jump to this page.
After obtaining the session information on this jsp page, pass the parameters through c: redirect and pass the required information in the session separately:
<C: redirect url = 'HTTP: // localhost: 8080/Project B/XXX.html '>
<C: param name = "orgName" value = "<% = sessionDto. getOrgName () %>"> </c: param>
<C: param name = "deptName" value = "<% = sessionDto. getDeptName () %>"> </c: param>
<C: param name = "personName" value = "<% = sessionDto. getPersonName () %>"> </c: param>
</C: redirect>
On the page B, obtain the url string passed through the url path and parameters. Note that, if the preceding parameters are obtained in Chinese, they are garbled like % e9 % 9b % 86% e5 % 9b % a2 % e6 % 9c % ac % e9 % 83% a8,
You must use the decodeURI () method for transcoding.

Now, the page of B is displayed. The following shows how to obtain the session information of:
First, configure it under the tomcat server. xml </Host> tab:
<Context docBase = ".. \ webapps \ Project A" path = "/A" reloadable = "true" crossContext = "true"/>
<Context docBase = ".. \ webapps \ Project B" path = "/B" reloadable = "true" crossContext = "true"/>
In the logon action of:
HttpSession session2 = request. getSession ();
Session2.setAttribute ("sessionDto", session information of );
ServletContext ContextA = session2.getServletContext ();
ContextA. setAttribute ("session", session2 );

Write a filter in web-inf/web. xml of B:
<Filter>
<Filter-name> sessionFilter </filter-name>
<Filter-class> com. XXX. util. sessionFilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-name> sessionFilter </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>
This function is used to obtain the session of A at any time when A is redirected to B.
In the doFilter method:
HttpSession session = request. getSession ();
ServletContext Context = session. getServletContext ();
ServletContext Context1 = Context. getContext ("/Project ");
If (Context1! = Null &&! Context1.equals ("")){
HttpSession session1 = (HttpSession) Context1.getAttribute ("session ");
Request. setAttribute ("sessionDto", session1.getAttribute ("sessionDto "));
}


To obtain the menu permission of A on the html page of B, call A jsp page in B through iframe on the page of B, this jsp page is used to obtain menu permissions,
<Iframe height = "100" width = "100" id = "getSessionIframe" src = "http: // localhost: 8080/Project A/pages/login/getSession. jsp "style =" display: none; "> </iframe>
Obtain the value on the iframe page on the html page of B:
Var userid=frames{'getsessioniframe'{.doc ument. getElementById ("userid"). value;
In this way, the menu permission of A is also obtained.

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.