Forums Register Login

Embedding a Tag in a scriplet

+Pie Number of slices to send: Send
Is it possible to do this? I've googled around and haven't come up with any obvious examples.

Thanks
+Pie Number of slices to send: Send
Short answer: no.

Perhaps a better long answer could be had if you could be more explicit on what you are trying to accomplish?
+Pie Number of slices to send: Send
Here's the scriptlet in question:

<%
int k = 0;
while (k < customFieldNames.size()) {
int z = k+1;
String placeHolder = (String)request.getAttribute("USER_DEFINED" + z);
out.println("<tr><td align=\"left\" valign=\"top\">");
out.println(customFieldNames.get(k) + ": ");
out.println("</td><td align=\"left\" valign=\"top\">");
if (placeHolder != null) {
out.println("<INPUT TYPE=\"TEXT\" NAME=\"userDefined" + (k + 1) + "\" size=\"20\" maxlength=\"500\" value=\"" + placeHolder + "\">");
} else {
out.println("<INPUT TYPE=\"TEXT\" NAME=\"userDefined" + (k + 1) + "\" size=\"20\" maxlength=\"500\">");
}
out.println("</td>");
out.println("</tr>");
k++;
}
%>

It's getting user defined fields from the request, and putting them in a cell next to the field. I'm trying to use the value of placeHolder as an argument to a tag-and was wondering if i embedded the tag in the body of the scriplet if that would work.
+Pie Number of slices to send: Send
Think about for a minute and you will see why it won't work. JSP tags (custom or otherwise) are translated into servlet code along with the rest of the JSP elements (e.g. scriplets) on the page. So tags are evaluated long before the JSP is executed to produce the output.

So any tags that you put in the output are sent to the browser as is, where they are ignored.

The big question is: why on earth are you writing HTML in scriplets? You are already in a JSP page -- just use template text for the output and you wouldn't be having this problem to begin with.
+Pie Number of slices to send: Send
Tobi,
In your example, you are trying to write out an HTML tag, not a JSP tag. This is legal because the HTML is just getting output to the stream and sent to the browser. It's a lot less awkward to use the templates as Bear suggested. Take a look at the two. Which is easier to read?





Your placeholder example isn't working because the quotes aren't properly matched. (I just copied the code; I didn't correct that in my first example.) Another reason it is easier to use the JSP as a template.

[edited to add line breaks]
[ February 28, 2005: Message edited by: Jeanne Boyarsky ]
+Pie Number of slices to send: Send
I didn't write the scriplet in question-it's legacy code. I'm just trying to put some new functionality into this particular JSP-and I'm just starting to learn the in's and out's of J2EE. Thanks again for the information.
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 858 times.
Similar Threads
Integrating web services to legacy system
retrieving parameter values from PreparedStatement
Display Tag: Sorting and Whitespaces
JSP parameter displays null String instead of empty string
xml to database
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:14:29.