This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

escape quotes

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
reply
    Bookmark Topic Watch Topic
  • New Topic