I know that you can use javascript inner html to change the content of the HTML code inside a <div>
tag. But is there anyone here who know of a way to change the content of HTML using other languages such as JSTL or scriptlets?
Asked
Active
Viewed 2,360 times
0

BalusC
- 1,082,665
- 372
- 3,610
- 3,555

user859385
- 607
- 1
- 6
- 23
1 Answers
2
I assume that you're fully aware that Java/JSP/JSTL runs at webserver and produces HTML/CSS/JS and that HTML/CSS/JS runs at the webbrowser. Thus, Java/JSP/JSTL has totally no notion of the client side HTML DOM tree like as JS has access to by the document
object. But Java/JSP/JSTL can be used to control the rendering of the HTML/CSS/JS output.
You could use JSTL and/or EL to conditionally display blocks of HTML/CSS/JS. E.g.
<div>
<c:if test="${condition1}">
<p>This block will only be rendered when condition1 evaluates true.</p>
</c:if>
<c:if test="${condition2}">
<p>This block will only be rendered when condition2 evaluates true.</p>
</c:if>
</div>
Using scriptlets is discouraged since JSP 2.0 (2003). So don't even think about it.
-
Yea i know it runs at the web server. Cause i wanna make a shopping cart. Looks like getting the java bean object from javascript is impossible. I thought i could change the html content using jstl and jsp. But like you said, jstl has no notion of the client side. Theres no choice but for me to use javascript now. Thank u – user859385 Aug 02 '11 at 13:04
-
1Can you please try to write like a professional developer, not like a teen? English is not my native language and your teen-like writing style ("i", "wanna", "cause", "u", etc) makes it for me harder to interpret you quickly. As to the question, truly JavaScript can access Javabean data. You just have to let Java/JSP/JSTL print it like as if it's a JavaScript object. Or you could just bring some Ajax magic in. If you elaborate about the concrete functional requirement for which you're actually looking for the solution, then we should be able to answer the right solution for that. – BalusC Aug 02 '11 at 13:08
-
Im terribly sorry about that. Never Mind, i found an alternative way for my assignment. Thank you. – user859385 Aug 02 '11 at 13:12