In a case of HTML I use document.getElementById("id"); in order to retrieve my desired element/tag.
How can I do that in case of a JSP file (let’s say inside a function)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you are confusing the terms HTML, JSP and JavaScript. The
document.getElementById("id")you mention in your question is a JavaScript snippet that, I guess is enclosed in a<script type="text/javascript"></script>tag (which is an HTML tag by the way).HTML is a markup language used to define how web pages looks like (well, actually is CSS the one in charge of the look & feel whilst HTML defines the page layout).
JavaScript is an interpreted language often embedded into the HTML and executed by your browser once the contents of the page are loaded.
JSP is another markup language based on HTML with several enhancements which allows to create dynamic web pages. JSP is executed by the server instead of the browser and the result of that execution is a HTML document. That generated HTML will contain references to CSS and JavaScript resources if the original JSP had. Even more, the JSP could use its ability to generate “dynamic content” to also generate “dynamic JavaScript snippets”.
So, the answer is: You can use JavaScript snippets in JSP just the same way you do in HTML code but you can’t use it inside Java methods embedded in the JSP as they are processed by the server, not the browser.