Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Embedding a Tag in a scriplet  RSS feed

 
Tobi McFarland
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to do this? I've googled around and haven't come up with any obvious examples.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer: no.

Perhaps a better long answer could be had if you could be more explicit on what you are trying to accomplish?
 
Tobi McFarland
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36393
453
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tobi McFarland
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!