J2EE后台response通过alert显示消息

本文主要介绍J2EE开发过程中,后台的response通过alert形式显示。(如:后台判断用户在db中不存在,前端alert提示“用户不存在”)

原理是前端画面onload时,通过js来判断errorMessage是否为空,不为空显示alert。

jsp 代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-logic" prefix="l" %>
<h:form action="bsm01DaLianInit.do">

<SCRIPT language="javascript">
function test(){
	<l:empty name="bsm01DaLianForm" property="errorMessage">
      alert("没有错误");
    </l:empty>

     <l:notEmpty name="bsm01DaLianForm" property="errorMessage">
		alert("有错误");
	</l:notEmpty>
    }
   window.onload = test;
</script>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    页面内容
                </td>
            </tr>
</table>
</h:form>


ActionForm代码

public class Bsm01DaLianForm implements Serializable {

    /** serialVersionUID */
    private static final long serialVersionUID = 1L;

    /** 错误消息 */
    private String errorMessage;

    /**
     * @return errorMessage を戻す。
     */
    public String geterrorMessage() {
        return errorMessage;
    }

    /**
     * @param errorMessage
     *            errorMessage を設定する。
     */
    public void seterrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值