0

I am trying to add HTML content into a div on page load. This HTML content is coming from a struts action class variable. I have tested that the I get the HTML content passed to the resultant jsp file but the problem is that I don't get how to add it inside a particular div from struts action class variable.

I want to append it to topcontblock div shown below:

<div class="main nobg">
<div class="topcontblock" id="contentBlock">
//my html content here
</div>
</div> 

I am really stuck on this. Any help would be greatly appreciated.

4

2 回答 2

1

您可以使用标签输出一个Struts2 Action变量(及其提供的):Getter<s:property />

<s:property value="yourVariableName"/>

默认情况下,出于安全原因,HTML变量中包含的标签在将其注入页面时会被转义(因此不会被评估)。为防止这种情况,您可以将属性修改escapeHtml为 false:

<s:property value="yourVariableName" escapeHtml="false" />

但是你应该停下来问问自己一个Action变量是否真的是你想要注入的片段的正确位置;最好在另一个 JSP 中定义它,并将其包含在<s:include />指令中。

于 2013-04-23T10:03:40.450 回答
0

您可以使用以下方法简单地添加它:

   $("div#contentBlock").html("here you can put your HTML code");

或者如果您将内容作为对象

   $("div#contentBlock").append($("<span>").addClass("your class"));
于 2013-04-23T08:36:23.207 回答