Two methods for obtaining the content of a child page from the parent page of two JSP pages: two methods: jsp
Requirement Description: Two JSP pages. The parent page requires 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 by id and does not want to import them using the <include> method. If there are too many templates, the entire parent page will be too large and loading will be slow. The following two solutions, I wonder if this problem has been solved.
1. ajax
Implementation process: Send an ajax request to the sub-page. After the sub-page obtains the parameter id and interacts with the js variable using java, the required template information is returned.
Disadvantage: Converting js variables to java variables is troublesome. You need to use form forms for submission. Besides, java scripts in jsp run on the server and require resource overhead on the server, and increases interactions.
2. Introduction through iframe
Implementation process: Use iframe to introduce the sub-page, and then get the required template through $ (iframe. contents (). find ("#" + id) [0]). val.
Disadvantage: I'm not sure if iframe can be delayed for loading. If I want to import the entire page like <include>, this method is not OK.
How does the java module in the jsp subpage obtain the variable value in the parent page js?
When you open the sub-page, it is OK to pass the value to the sub-page;
If you do not want to pass the value, use the onload method on the subpage to write the value call to the subpage using js, and then call it in java, however, the premise is that the parent page needs to write the values in js using hidden labels on the page;
How does jquery obtain objects in child pages in parent pages?
Two points
1. Now that you use jQuery, why do you need to use getElementById () to retrieve elements? Besides, it's not that difficult to get the element in iframe.
$ ("# Id_iframe"). contents (). find ("# id_button_test"); that's not enough ..
2. Have you written this part of the Code on the. jsp page? I guess it is because the B. jsp page is not loaded when you register the click event. So even if you can output data during debugging, the Code cannot be registered. Write this code in the window. onload event of B. jsp.