web项目弹提示框小技巧
??window.location=goUrl;
?}else if(msg!="" && goUrl=="back"){
??alert(msg);
??history.back();
?}else if(msg!="" && goUrl!="back"){
??alert(msg);
??window.location=goUrl;
?}
}
?
然后我们需要建一个接口类
public interface MyMsg {
?String ADD_SUCCESS = "addSuccess";
?String ADD_FAIL = "addFail";
}
?
再来建一个jsp页面 showMsg.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
??? <title>提示信息</title>
? <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/sqb.js"></script></head>??
? <body>
??? <c:set var="msg" value="${map.msg}" />
<c:choose>
??? <c:when test="${msg=='delSuccess'}">
??????? <script type="text/javascript">alertMsg("删除成功","跳转页面");</script>
??? </c:when>?
??? <c:when test="${msg=='delFail'}">
??????? <script type="text/javascript">alertMsg("删除失败.","跳转页面");</script>
??? </c:when>
</c:choose>
</body>
</html>
?
再action里面我们就可以这样写
public class?test extends ActionSupport?implements MyMsg{
????? @Action(value="activityList",results = {@Result(name=SUCCESS,location =?"/showMsg.jsp")})
????? public String test(){
??????? ?map.put("msg",ADD_SUCCESS);
?????? ? return SUCCESS;
?}
}
?
这样我们就完成了