本来是跳转到新页面显示错误信息,现在需要在点击按钮时,就直接在原来的页面上弹出提示信息.
action中的方法如下:
public String sendEmail() throws Exception {
MailBean mailBean = setMailBean();
try {
if(!isWriteRight(mailBean,mailInfoFB.getTo())){
mailInfoFB.setSended(false);
mailInfoFB.setFrom("收件人错误,请检查您填写的收件人是否有误!");
deleteAttachment();// 发完信息时删除硬盘中的附件信息
return "sendMailSuccess";
}
}
Struts的信息
<action name="sendMail" class="userSendMailAction">
<result name="success">/user/user_send_mail.jsp</result>
<result name="sendMailSuccess">/user/user_sendMail_success.jsp</result>
<interceptor-ref name="loginInterceptor" />
</action>
jsp中的代码
<input type="button" title="发信" value="发 信" onclick="checkTo()"/>
function checkTo(){
var to =$.trim($("#i_receive").val());
var sub = $("#i_subject").val();
var con = $("#i_content").val();
var cc =$.trim($("#i_cc").val());
var bcc =$.trim($("#i_bcc").val());
if(to == "" || to.length==0){
alert("请填写联系人!");return ;
}
if(sub == "" || sub.length==0){
alert("请填写邮件主题!");return ;
}
if(to != "" && to.length>0){
if(!reg.test(to)){
alert("你输入的收件人地址不正确!");return ;
}
}
if(cc != "" && cc.length>0){
if(!reg.test(cc)){
alert("你输入的抄送人地址不正确!");return ;
}
}
if(bcc != "" && bcc.length>0){
if(!reg.test(bcc)){
alert("你输入的密送人地址不正确!");return ;
}
}
showProgress("正在发送邮件...");//显示保存进度
$("#sendmail").submit();
}
增加form
`<form action="<%=basePath %>user/sendMail!sendEmail.action" method="post" id="sendmail">