Two methods for parent pages of two JSP pages to obtain the content of child pages

  • 2021-07-03 00:44:19
  • OfStack

Requirements: For two JSP pages, the parent page needs the content of the child page, but the child page is hidden. Specifically, the child page is a series of templates. The parent page needs to obtain these templates through id, and is unwilling to pass < include > Mode import, because if the template is too much, it will lead to the whole parent page is too large, slow loading, the following two programs, I do not know whether to solve this problem.

1. Through ajax mode

Implementation process: Request to the sub-page through ajax. After the sub-page obtains the interaction of parameter id using java and js variables, return the required template information

Disadvantages: Converting js variables into java variables is more troublesome and needs to use form form to submit, and java scripts in jsp run on the server side, which requires server-side resource overhead and increases the number of interactions

2. Introduced through iframe

Implementation: Introduce the child page using iframe, and then get the required template through $(iframe. contents (). find ("#" + id) [0]). val ().

Disadvantages: Not sure if iframe can delay loading, if you want to < include > 1 to import the whole page, this method is not ok.


Related articles: