Struts2从字符串插入html

Mad*_*ada 0 html struts2

是否可以通过Struts将变量从java文件传递到jsp,并且该变量本身包含html?(如“<p>你好</p>”)。然后我想将此变量的内容粘贴到 jsp 文件中,它应该创建新的 html 内容。你能给我一个建议吗,因为我是初学者,我不知道如何使用它..谢谢

Ume*_*thi 5

是的,这是很有可能的,您可以从操作类发送一个简单的字符串,并可以在 JSP 中检索它,例如

public class MyClass extends ActionSupport{

 private String myHTMLCode;
 //getter method
 //setter
  public String execute() throws Exception{
     myHTMLCode=// fill it with your HTML
  }

}
Run Code Online (Sandbox Code Playgroud)

在 JSP 中

<s:property value="myHTMLCode" escapeHtml="false"/>
Run Code Online (Sandbox Code Playgroud)

Struts2 标签具有属性,即escapeHtml告诉底层框架天气是否转义 HTML,并且属性标签默认为 true