Wednesday, April 15, 2015

Alert for Success of process using Struts

in Action File We need to set
if(flag==true)
            {
                req.setAttribute("msg",str);
                if(type.equals("APP"))
                    req.setAttribute("url","####.do");
                else
                    req.setAttribute("url","####.do?code="+code);                  forward=mapping.findForward("success");
            }
in Struts Config
<action path="/###" type="ActionName" parameter="Method" scope="request">
            <forward name="success" path="/Success.jsp" />
            <forward name="error" path="/Error.jsp" />
        </action>

<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="../css/<%=session.getAttribute("pageCss")%>">
  </head>
  <body class="bg">
<%String fwd=(String)request.getAttribute("fwdlink");
//System.out.println("fwd link is"+fwd);

%>

<%
if(fwd==null)
{
fwd=(String)request.getAttribute("url");
}
%>

    <script>
    var msg="<%=request.getAttribute("msg")%>";
    alert(msg);
    location.replace("<%=fwd%>");
    </script>
  </body>
 
</html>

No comments:

Post a Comment