File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Rendering html string from action class to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Rendering html string from action class to jsp" Watch "Rendering html string from action class to jsp" New topic
Author

Rendering html string from action class to jsp

Irus Albert
Greenhorn

Joined: Sep 14, 2010
Posts: 7
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 14, 2010
Posts: 7
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 14, 2010
Posts: 7
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

Joined: Sep 29, 2008
Posts: 12617

The escapeHtml attribute was added at some point, in earlier versions it was just "escape".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rendering html string from action class to jsp
 
Similar Threads
I cannot obtain the enitre path of image
Retrieving information from previous page's form
"MVC" controller servlet
jsp form with two submit button
ServletException in:/pages/logon.jsp] Cannot retrieve definition for form bean null'