my dog learned polymorphism*
The moose likes JSP and the fly likes Getting HTML code from a java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting HTML code from a java bean" Watch "Getting HTML code from a java bean" New topic
Author

Getting HTML code from a java bean

Oliver Moore
Ranch Hand

Joined: Mar 04, 2003
Posts: 44
Hi all...
I have a text area which I use to place text into a database. I had hoped that I would be able to also place html code in in this text box, upload it to a database as type text, retrieve it using a java bean, use a <bean:write> tag to write it into the JSP page, and have the page display it as if it was html code embedded directly into the page.
I think that part of the problem is that characters such as < are getting converted into <. The data is stored correctly in the MySQL database, so there must be a conversion when it is placed in the bean using the get or set method.
The data is being stored as a String variable in the bean... could this be the problem? The type of data in the db table is specified as text.
Any ideas on how to proceed would be great. I'm trying to store html as I would like users to be able to modify the information in an html table by editing the code.
Thanks,
Ols


Regards,<p>Ols
Oliver Moore
Ranch Hand

Joined: Mar 04, 2003
Posts: 44
Update: Have refined the issue to this...
I enter the following in a textarea

and insert it into a database. Later, I then retrieve this, and display it in a page using the <bean:write property /> tag. This results in the above code being displayed, rather than an HTML table being created. However, if I look at the source code of the page, the below code is shown (have had to insert spaces to show problem, else it renders as the original charaters):

How do I make the code display the correct characters i.e. <,> etc such that the browser renders it as code rather than text?
Thanks...
[ December 29, 2003: Message edited by: Oliver Moore ]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The transformation is probably being performed in bean:write. What I suggest is that you provide a new method in your bean which just returns the string you wish to display, and call it using <%= whateverMyBeanIsCalled.whateverMyMethodIsCalled() %>
With any luck this should avoid the transformation.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting HTML code from a java bean