Struts2 special symbol replacement, struts2 special symbol

Source: Internet
Author: User

Struts2 special symbol replacement, struts2 special symbol

Today, I used struts2 As a small example and found a problem.

The action Code is as follows:

  private String table;    public String execute(){        setName("peter");        setTable("<tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr>");        return SUCCESS;    }    public String getTable() {        return table;    }    public void setTable(String table) {        this.table = table;    }

Then, when the page is called

<table id="mytable" border="1">      <tr><td>1232312321312</td></tr>      <s:property value="table"/>  </table>

The result is as follows:

Did not get the expected results, right-click to view the source code, the code is as follows:

<table id="mytable" border="1">      <tr><td>1232312321312</td></tr>      &lt;tr&gt;&lt;td&gt;1232312321312&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1232312321312&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1232312321312&lt;/td&gt;&lt;/tr&gt;  </table>

Struts2 replaces "<" and ">" with html encoding.

After finding a number of methods, you cannot solve the problem. In the end, you can only discard the expression and directly obtain the data in the action.

<table id="mytable" border="1">      <tr><td>1232312321312</td></tr>      <%=request.getAttribute("table") %>  </table>

Then the effect is displayed.

The background code is also normal.

<table id="mytable" border="1">      <tr><td>1232312321312</td></tr>      <tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr>  </table>

The cause is unknown, but the problem is resolved ~~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.