Using JavaScript to eliminate the div s and other elements without information in JSP dynamically generated pages

In the process of using jsp technology to dynamically generate pages
Because our pages are generated dynamically by a jsp file
So not every page is suitable

We need to extract information from the database and dynamically generate jsp pages that can display every page normally
But information is not necessarily complete
In this way, some empty elements will appear in some pages, that is, div s without content or other elements

Before that, I also considered whether I could dynamically check whether the session or json passed in is empty when jsp generates html page
Output if not empty
Unfortunately, I didn't find a proper way to solve this problem from jsp

Finally, I thought of using JavaScript to check when the page is generated
Hide the empty innerHTML element

Example code:


                    $(document).ready(
                        function(){
                            var label;
                            label = document.getElementById("label1");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }
                            label = document.getElementById("label2");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }
                            label = document.getElementById("label3");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }
                            label = document.getElementById("label4");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }
                            label = document.getElementById("label5");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }
                            label = document.getElementById("label6");
                            if(label.innerHTML == "" || label.length == 0 ){
                                label.style.display = "none";
                            }

                            var makingway;
                            makingway = document.getElementById("makingway1");
                            if(makingway.innerHTML == "" || makingway.length == 0 ){
                                makingway.style.display = "none";
                            }
                            makingway = document.getElementById("makingway2");
                            if(makingway.innerHTML == "" || makingway.length == 0 ){
                                makingway.style.display = "none";
                            }
                            makingway = document.getElementById("makingway3");
                            if(makingway.innerHTML == "" || makingway.length == 0 ){
                                makingway.style.display = "none";
                            }
                            makingway = document.getElementById("makingway4");
                            if(makingway.innerHTML == "" || makingway.length == 0 ){
                                makingway.style.display = "none";
                            }
                            makingway = document.getElementById("makingway5");
                            if(makingway.innerHTML == "" || makingway.length == 0 ){
                                makingway.style.display = "none";
                            }

                            var effect;
                            effect = document.getElementById("effect1");
                            if(effect.innerHTML == "" || effect.length == 0 ){
                                effect.style.display = "none";
                            }
                            effect = document.getElementById("effect2");
                            if(effect.innerHTML == "" || effect.length == 0 ){
                                effect.style.display = "none";
                            }
                            effect = document.getElementById("effect3");
                            if(effect.innerHTML == "" || effect.length == 0 ){
                                effect.style.display = "none";
                            }
                            effect = document.getElementById("effect4");
                            if(effect.innerHTML == "" || effect.length == 0 ){
                                effect.style.display = "none";
                            }
                            effect = document.getElementById("effect5");
                            if(effect.innerHTML == "" || effect.length == 0 ){
                                effect.style.display = "none";
                            }
                        }
                    )


Tags: JSP Database Session JSON

Posted on Mon, 04 May 2020 04:58:58 -0400 by montana111