用<s:actionmessage/>标签显示Action信息时,有一个要注意的地方,
就是相应Action的配置
<!-- 修改帐号密码 -->
<action name="updatePassword" class="userAction" method="updatePassword">
<result name="input">/account/updatePassword.jsp</result>
<result name="success" type="redirect" >/account/updatePassword.jsp</result>
</action>
注意:
如果将result标签的type属性设置为redirect则在Action即使使用了
addActionMessage(getText("updatePassword.success"));
或
addActionMessage(super.getText(e.getMessage()));
在jsp页面也不能显示相应的信息
问题二:
ActionMessage里的值怎么在jsp页面alert出来?
首先得明白一点,ActionMessage是struts后台的对象,而alert是网页前台的东西
最方便的方法是直接把ActionMessage的值使用标签输出到页面中的某一个div或span元素中(注意,要隐藏)
然后在需要alert的地方,得到这个div的innerHTML即可。
例如:
<body>
<span id="message" style="display:none;">
<s:actionmessage />
</span>
</body>
var msg=document.getElementById("message").innerHTML
alert(msg);
或者
function onunload_handler(){
//$(".actionMessage").html()
if($(".actionMessage")[0].innerText =="保存成功"){
alert("创建完成!点击确定关闭本窗口!");
opener.location="javascript:refresh()";
window.close();
}
}