• Post Reply Bookmark Topic Watch Topic
  • New Topic

escape quotes

 
harmeet bawa
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what i am trying to do:

I generate the html for a jsp in a java class. For that I am appending the html to a string buffer.
eg.
stringbuffer.append("<input type='text' name='name' value='<jsp:getProperty name=\"beannabe\" property=\"propertyname\" />'>");

when I print the value of the stringbuffer on the jsp it is just displaying the '<jsp:getProperty name=\"beannabe\" property=\"propertyname\" />' as is and not getting the value of the property form the bean.
What is it that I am doing wrong here?

Thnx in advance
Harmeet
[ January 24, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot embed JSP standard (or custom) actions in HTML created at run-time. The time for processing actions like jsp:getProperty is long passed.

Please read this article for more information on how JSPs work and their life-cycle.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to see "what's wrong with this picture?" let's look at the sequence of events that occur when your browser requests "myPage.jsp".

1- The Web Container recognizes this as JSP file and sends it to the JSP Compiler
2- The JSP compiler reads your <jsp:xxx>, JSTL tags, etc. and converts them into java code.
3- The java code generated by the JSP compiler is converted to byte code (a .class file) and executed.
4-The execution of the .class file produces raw HTML that is then sent back to the browser


Ok, now, given what you're trying to do: "What's wrong with this picture?"

Answer: The output of your bean is realized and put into the output stream being sent to the browser [b]after{/b] the JSP compiler has already been called. That means that any <jsp:xxx> tags that you put in the stream will not be interpreted by the JSP compiler. What you're doing will work only if the bean produces plain old HTML tags without any JSP tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you generating HTML in a Java class instead of within the JSP?

Is this in a tag handler?
 
harmeet bawa
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx guys. any suggestions to do what I am doin?
[ January 24, 2006: Message edited by: harmeet bawa ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by harmeet bawa:
any suggestions to do what I am doin?


My first suggestion is to answer my questions.
 
harmeet bawa
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am generating the html in a java class to keep the colde clean. its just like i go and look uo in the database for the entried already present for the use in the java class and then spit them out on the jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by harmeet bawa:
i am generating the html in a java class to keep the colde clean.


Sorry, but generating HTML in Java code is anything but clean and should be avoided if at all possible.

If the HTML were in the JSP, you wouldn't be having this issue. My recommendation is to move the HTML into the JSP and pass data to the JSP page to fill in the dynamic portions.
 
Saskia de Jong
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


Sorry, but generating HTML in Java code is anything but clean and should be avoided if at all possible.


In the case of what the OP is trying to do you're definitely right. However, when dealing with custum tags (especially when they come in the form of JSF) you're not doing anything BUT generating HTML in Java code
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Saskia de Jong:

However, when dealing with custum tags


Which is why I said "whenever possible" and why I asked if this was tag handler code earlier...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!