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> <tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr><tr><td>1232312321312</td></tr> </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 ~~~~