Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rendering html string from action class to jsp

 
Irus Albert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an action class (not a Servlet) and a jsp, with an xml file as the controller. My action class interacts with an external interface and gets a string as response. This string is actually a html code

eg String s ="<html><table><tr>Hello</tr></table></html>"

I return a success string and my controller thus forwards to the appropriate jsp. This jsp has access to the string s. Now, I want to print the response out as html.

I tried <%=s%>
and out.print(s)

But, they are not working. The rest of the jsp is using struts tags like

<s:property> etc

So, I tried <s:include value="%{s}" /> But, since s is not a url, this is giving some error.

I dont know why scriplets are not working. Could you guide me.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you putting the string into scope?

(And how can an XML file be a controller? It's just data.)

Moving to Struts.
 
Irus Albert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Thing is there are no scope variables or sessions. And my jsp is not on a servlet container but web. Struts 2 tags are being used and I am finding it hard to follow.

The basic problem is how to render an html string as html and not just print it as a string!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Irus Albert wrote:my jsp is not on a servlet container but web

I have no idea what that means.

In Struts 2 actions themselves are in scope. If the action exposes the property then it's available. The <s:property> tag has an escapeHtml attribute that controls if HTML is escaped or not.
 
Irus Albert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. Thing is if i do

<s:property value="s"/>

I am getting the string as it is as the output which is not what I want. I am looking for a solution to this.

I tried searching for escape html, but unable to find it.

I tried <s:property value="%{s}" /> as well, but am not getting the html output.

s is a string here
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The escapeHtml attribute was added at some point, in earlier versions it was just "escape".
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic