J2EE后台response通过alert显示消息

来源:互联网 发布:c语言 戏说关键字 ppt 编辑:程序博客网 时间:2024/05/22 05:04

本文主要介绍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;    }}



1 0
原创粉丝点击