页面跳转的总流程为:
1、根据自己命名的URL :http://localhost:7001/ecs_local/public/threeBBOnlineVas/threeBBOnlineVasService.do?lang=zh-HK&method=init
它会根据threeBBonlineVasService.do去找到ThreeBBOlineVasAction这个Action类,然后根据method=init去匹配执行这个Action类的init()函数
2、在init函数中执行到return mapping.findForward("select");这一句就会到配置文件struts-config.xml这里面找到匹配"select"这个字符串跳到默认的主页3BB_LeSportsNBA_Select.jsp这里来。
3、在3BB_LeSportsNBA_Select.jsp这个页面中写上关键的一句<input type="hidden" name="method" value="SelectAccount" />
然后提交from表单到Action类threeBBOnlineVasService.do这个中去,进入Action后它会根据这个字符串"SelectAccount"去匹配
执行对应的函数SelectAccount()。
4、之后又和上面一样执行到return mapping.findForward("SelectAccount");这一句后,就会到配置文件struts-config.xml这里面找到匹配跳到下一个页面3BB_LeSportsNBA_SelectAccount.jsp这里来。之后以此类推。
具体实现代码如下:
1、ThreeBBOlineVasAction.java
package com.hgc.ecs.web.threeBBOnlineVas.action; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import com.hgc.ecs.web.onlineVas.dao.CreateVASOrderDAO; import com.hgc.ecs.web.onlineVas.service.CreateVASOrderService; import com.hgc.ecs.web.threeBBOnlineVas.bean.loginMessage; import com.hgc.ecs.web.threeBBOnlineVas.util.GetLoginMessage; public class ThreeBBOlineVasAction extends DispatchAction { private final Log log = LogFactory.getLog(ThreeBBOlineVasAction.class); int a = 0; int b = 0; int c = 0; /* * public ActionForward execute(ActionMapping mapping, ActionForm * actionForm, HttpServletRequest request, HttpServletResponse response) * throws Exception { * * String page = request.getParameter("type"); * * if ("SelectAccount".equals(page)) { return mapping.findForward(page); } * return mapping.findForward("SelectAccount"); } */ public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { this.log.info("Comging Home Page ..."); return mapping.findForward("select"); } public ActionForward SelectAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String Name = request.getParameter("hiddenName"); String Number = request.getParameter("hiddenNumber"); String MobileNumber = request.getParameter("hiddenphoneNumber"); List<loginMessage> resultList = new ArrayList<loginMessage>(); String sign, servType, acctNo, contNo, acctStat, contStat, subNo, contractEndDate, totalAmntDue, custName; this.log.info("Name:" + Name + "-------" + Number + "----------" + MobileNumber); GetLoginMessage gm = new GetLoginMessage(); resultList = gm.getLoginMessage(Number, Name); sign = resultList.get(0).getSign(); request.setAttribute("result", resultList); response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); // 不符合资格的在前台不允许跳到下个页面并且弹框提示 if (sign.equals("false")) { return mapping.findForward("select2"); } return mapping.findForward("SelectAccount"); } public ActionForward comfirm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("comfirm"); } public ActionForward complete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String strAccountNo = request.getParameter("accountNumber"); String strAcctNo = ""; String strContNo = ""; if (strAccountNo != null && strAccountNo != "") { strAcctNo = strAccountNo.substring(0, 8); strContNo = strAccountNo.substring(8, 11); } String strOfferId = request.getParameter("offerid"); String strSmsCode = request.getParameter("hiddenphoneNumber"); String sale_code = request.getParameter("sale_code"); CreateVASOrderService service = new CreateVASOrderService(); String strResult = service.Inert(strAcctNo, strContNo, strOfferId, strSmsCode, sale_code); if (strResult != "") { return mapping.findForward("complete"); } else { return mapping.findForward("complete"); } } }2、struts-config.xml
<!-- OnlineVas 3BB By Cong 20170420 --> <action parameter="method" path="/public/threeBBOnlineVas/threeBBOnlineVasService" type="com.hgc.ecs.web.threeBBOnlineVas.action.ThreeBBOlineVasAction" scope="request"> <forward name="select" path="/OnlineVas_3BB/3BB_LeSportsNBA_Select.jsp" /> <forward name="select2" path="/OnlineVas_3BB/3BB_LeSportsNBA_Select.jsp?type=error" /> <forward name="comfirm" path="/OnlineVas_3BB/3BB_LeSportsNBA_Confirm.jsp" /> <forward name="SelectAccount" path="/OnlineVas_3BB/3BB_LeSportsNBA_SelectAccount.jsp" /> <forward name="comfirm2" path="/OnlineVas_3BB/3BB_LeSportsNBA_Confirm.jsp?type=error" /> <forward name="complete" path="/OnlineVas_3BB/3BB_LeSportsNBA_Complete.jsp" /> <forward name="sspselect" path="/OnlineVas_3BB/3BB_LeSportsNBA_Select.jsp" /> <forward name="sspcomfirm" path="/OnlineVas_3BB/3BB_LeSportsSSP_Confirm.jsp" /> <forward name="sspcomfirm2" path="/OnlineVas_3BB/3BB_LeSportsSSP_Confirm.jsp?type=error" /> <forward name="sspcomplete" path="/OnlineVas_3BB/3BB_LeSportsSSP_Complete.jsp" /> </action>3、3BB_LeSportsNBA_Select.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/tags/struts-bean" prefix="bean"%> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <meta name="description" content=""> <meta name="author" content=""> <% String ctxPath = request.getContextPath(); String sign=request.getParameter("type"); %> <!-- Bootstrap core CSS --> <link href="<%=ctxPath%>/OnlineVas_3BB/css/bootstrap_OnlineVAS.css" rel="stylesheet"> <link href="<%=ctxPath%>/OnlineVas_3BB/css/eAccount.css" rel="stylesheet"> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> <!-- Custom styles for this template <link href="css/carousel.css" rel="stylesheet"> --> </head> <script type="text/javascript"> function pop2() { if (event.keyCode == 13) { pop(); return false; } } function pop() { var MobileNumber = $("#inputMobileNumber").val(); var Number = $("#inputNumber").val(); var Name = $("#inputName").val(); var mobile = MobileNumber.substr(0, 1); if (Name == "") { alert("請輸入正確的登記姓名"); return false; } if (Number == "" || Number.length != 6) { alert("請輸入正確的身份証首六位數字"); return false; } if (MobileNumber == "" || MobileNumber.length != 8 || (mobile != 5 && mobile != 6 && mobile != 8 && mobile != 9)) { alert("請輸入正確的電話號碼"); return false; } if("<%=sign %>" == "error") { alert('你所輸入的登記姓名或身分證首6位數字不正確, 請重新輸入'); return false; } else { $("#hiddenphoneNumber").val(MobileNumber); $("#hiddenNumber").val(Number); $("#hiddenName").val(Name); $("#form1").submit(); } } </script> <body> <form id="form1" name="form1" action="<%=ctxPath%>/public/threeBBOnlineVas/threeBBOnlineVasService.do" method="post"> <input type="hidden" name="method" value="SelectAccount" /><input type="hidden" id="offerid" name="offerid" value="O1735333"> <input type="hidden" id="period" name="period" value="12"> <input type="hidden" id="fee" name="fee" value="$250"> <div class="container"> <div class="clearfix"> <nav> <ol class="breadcrumb"> <h3 class="text-muted">立即申請</h3> <li class="active">選擇賬戶及組合</li> <li>確認購買組合</li> <li>申請完成</li> </ol> </nav> </div> <div> <img src="<%=ctxPath%>/OnlineVas_3BB/images/LeSportsNBA_banner.png" alt="Cinque Terre" width="930" class="img-responsive"> </div> <div> <h4>LeSports NBA 組合現已提供予3家居寬頻客戶選擇。立即申請盡情收看NBA 賽事</h4> </div> <div class="row marketing"> <div class="panel panel-default"> <div class="panel-body"> <div class="col-lg-8"> <div class="VAS_content"> <h4 class="header">3 家居寬頻 LeSports NBA 組合*</h4> <div>服務內容</div> <ul style="padding-left: 15px;"> <li>每季超過500場精選NBA賽事直播及重播, 包括常規賽、季後賽及明星賽。</li> </ul> <div>最少申用期:24個月</div> <div>月費:$39</div> </div> </div> <div class="col-lg-4"> <div class="vcenter heroVCenter"> <div class="plan-price hero"> <div> <p>$39</p> <p>/month</p> </div> </div> </div> <p> <a data-toggle="modal" data-target="#myModal" href="#example" class="btn btn-primary btn-lg btn-block">立即申請</a> </p> </div> </div> </div> <div class="help-block">* 只適用於指定之大廈及指定特選 3 家居寬頻服務現有客戶。</div> </div> <div></div> </div> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">3家居寬頻客戶登入</h4> </div> <div class="modal-body"> <div class="form-horizontal" role="form"> <div class="form-group"> <label class="col-sm-3 control-label">登記姓名</label> <div class="col-sm-8"> <input type="text" class="form-control" id="inputName" οnkeypress="return pop2();" placeholder="請輸入姓名"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">身份証首六位數字</label> <div class="col-sm-8"> <input type="text" class="form-control" id="inputNumber" οnkeypress="return pop2();" placeholder="請輸入身份証首六位數字"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">*手機號碼</label> <div class="col-sm-8"> <input type="text" class="form-control" id="inputMobileNumber" οnkeypress="return pop2();" placeholder="請輸入手機號碼"> <input type="hidden" id="hiddenphoneNumber" name="hiddenphoneNumber" value=""><input type="hidden" id="hiddenNumber" name="hiddenNumber" value=""><input type="hidden" id="hiddenName" name="hiddenName" value=""> </div> </div> </div> </div> <div style="padding-left: 15px;"> <span class="help-block">* 當你忘記戶口登入密碼時,重設密碼之短訊將發送至此號碼</span> </div> <div class="modal-footer"> <!-- 3BB_LeSportsNBA_SelectAccount.jsp --> <a href="#" οnclick="pop()" class="btn btn-primary">提交</a> <a href="#close" class="btn btn-primary" data-dismiss="modal">取消</a> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="<%=ctxPath%>/OnlineVas_3BB/js/jquery.min.js"></script> <script src="<%=ctxPath%>/OnlineVas_3BB/js/bootstrap.min.js"></script> <!-- Just to make our placeholder images work. Don't actually copy the next line! --> <script src="<%=ctxPath%>/OnlineVas_3BB/js/holder.min.js"></script> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <script src="<%=ctxPath%>/OnlineVas_3BB/js/ie10-viewport-bug-workaround.js"></script> <script src="<%=ctxPath%>/OnlineVas_3BB/js/ie-emulation-modes-warning.js"></script> </form> </body> </html>