简体   繁体   中英

How to use jsp include tag in javascript

I have created on page that page has one button as the user click on that button new row inserted with input field and drop down box. i have to show the dynamic value in drop down which is using from XMl. For that i have created one page getdata.jsp which return value1value2. I have included that page in index.html where i want to show drop down. but problem is when i trying to use inculde tag in java script that is no working. I have to include this page in my index.jsp so that drop down will create dynamical.

I want to include my page here

cell4.innerHTML ="<%@include file="getdata.jsp" %>";

How can i achieve this. Thanks

A couple thoughts for you.

This is usually done with an ajax request rather than a direct include like this. This allows you to refresh the data at any time and keeps better separation between your server side and client side code. It looks something like this:

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        cell4.innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.open("GET","getdata.jsp",true);
xmlhttp.send();

Alternatively if you really want to include the jsp file like this you'll need to include it from a jsp file as well. Currently your script is most likely in a ".js" file. Your webserver will not process this like a jsp file and your include will be ignored. You can change this to a ".jsp" and update the script tag's src attribute. I don't recommend this approach however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM