日期:2014-05-16  浏览次数:20722 次

数据操作后,页面alert提示例子2-ajax实现

1.页面

?? js文件:tipMessage.js

??

function showTipMesage(){
	$.ajax({
		   type: "POST",
		   url: "showTipMessage.action",
		   async: false,
		   success: function(msg){
		    if(msg!="null"){
		     alert( msg );
		    }
		   }
		});
}

?? 调用

???

<script type="text/JavaScript">
 showTipMesage();
... other code

?

??

2.baseAction配置文件xml

?? <action name="showTipMessage" class="baseAction" method="showTipMessage">

3.后台BaseAction.java代码-获得提示信息

?

  public String showTipMessage() throws IOException{
        HttpServletRequest request = ServletActionContext.getRequest();
        String tipMessage=(String) request.getSession().getAttribute("tipMessage");
        HttpServletResponse response = ServletActionContext.getResponse();
        if(tipMessage==null){
     	   tipMessage="null";
        }
        response.getWriter().write(tipMessage);
        request.getSession().removeAttribute("tipMessage");
        return null;
     }

?

4.后台BaseAction.java代码-添加提示信息

?

? public void addTipMessage()(String msg) {
????? ServletActionContext.getRequest().setAttribute("message", message);
???}

?

?

?