在xml中使用&和字符

之前在写struts2配件文件的时候需要用到&,但是用的时候提示错误

<action name="city" class="CityAction">
        <result name="success" type="redirect">/sight.html?id=${id}&amp;message=${message}</result>
        <result name="error" type="dispatcher">error.jsp</result>
</action>

下面是五个在XML文档中预定义好的实体: 
&lt;             <        小于号  
&gt;            >        大于号 
&amp;       &        和  
&apos;       '         单引号 
&quot;        "         双引号 

      实体必须以符号"&"开头,以符号";"结尾。
  如果在XML文档中使用类似"<" 的字符, 那么解析器将会出现错误,因为解析器会认为这是一个新元素的开始。所以不应该像下面那样书写代码: 
<message>if salary < 1000 then</message>  
  为了避免出现这种情况,必须将字符"<" 转换成实体,像下面这样:  
<message>if salary &lt; 1000 then</message>  
  注意: 只有"<" 字符和"&"字符对于XML来说是严格禁止使用的。剩下的都是合法的,为了减少出错,使用实体确实是一个好习惯

原文地址:https://www.cnblogs.com/iusmile/p/2571192.html