找回密码
 FreeOZ用户注册
查看: 1762|回复: 9
打印 上一主题 下一主题

[论坛技术] struts problem 2( hoopoos 请进谢谢)

[复制链接]
跳转到指定楼层
1#
发表于 15-1-2010 15:25:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册

x
  1. public class PayrollUploadJobStatusAction extends SecureAction
  2. {       
  3.         Properties props = new Properties();

  4.         /**
  5.          * @see SecureAction#securePerform(ActionMapping, ActionForm, ActionContext, HttpServletRequest, HttpServletResponse)
  6.          */
  7.         public ActionForward securePerform(ActionMapping mapping,
  8.                 ActionForm form,
  9.                 ActionContext actionContext,
  10.                 HttpServletRequest request,
  11.                 HttpServletResponse response)
  12.         throws IOException, ServletException        {
  13.       
  14.                 String forwardAction = Constants.ACTION_SUCCESS;
  15.                 getErrors(request);
  16.                 String saveUrl ="PayrollBatchJobStatus.jsp";        
  17.         
  18.         //Check the status of importing
  19.         String payrollFileId = request.getParameter("payrollFileId");
  20.         PayrollFileBean pfBean = PayrollFileDao.retrieveByPayrollFileId(actionContext.getConnection(), (new Integer(payrollFileId)).intValue());
  21.         
  22.         if (pfBean != null && (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED
  23.           || pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORT_FAILED)) {   
  24.          
  25.             forwardAction = Constants.ACTION_SUCCESS;
  26.            
  27.             ClientPayrollUploadJobStatusForm statusForm = new ClientPayrollUploadJobStatusForm();
  28.             if (form != null)
  29.                 statusForm = (ClientPayrollUploadJobStatusForm)form;
  30.             
  31.             if (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED)
  32.               statusForm.setAction(Constants.ACTION_SUCCESS);
  33.             else
  34.               statusForm.setAction(Constants.ACTION_FAILURE);
  35.             
  36.             List logs = IbasLogDao.retrieveByBatchId(actionContext.getConnection(), pfBean.getImportBatchId());
  37.             Iterator it = logs.iterator();
  38.             List msgList = new ArrayList();
  39.             while (it.hasNext()) {
  40.               com.rem.ibas.model.bean.IbasLogBean logBean = (com.rem.ibas.model.bean.IbasLogBean)it.next();            
  41.               msgList.add(logBean.getDescription());
  42.             }
  43.             
  44.             //statusForm.setOriginalMessage(msg);
  45.             statusForm.setPayrollFileId(pfBean.getPayrollFileId().toString());
  46.             request.setAttribute("msgList", msgList);
  47.         }
  48.                 else {
  49.                         forwardAction = Constants.ACTION_FAILURE;
  50.                        
  51.                         //use another object to avoid modifying orginal one
  52.                         ActionForward tempActionForward = new ActionForward();
  53.                         //Construct query string for forwardAction is success
  54.                         tempActionForward.setPath("/" + saveUrl);
  55.                         return (tempActionForward);
  56.                 }
  57.                
  58.                 return (mapping.findForward(forwardAction));
  59.         }
  60. }
复制代码
Struts config
  1. <action path="/payrollUploadJobStatus"
  2.                 type="com.rem.ibas.model.action.PayrollUploadJobStatusAction"
  3.                 name="ClientPayrollUploadJobStatusForm"
  4.                 validate="false"
  5.                 scope="request">
  6.                 <forward name="success"
  7.                          path="/ClientPayrollImportResult.jsp"
  8.                          redirect="false">
  9.                 </forward>
  10.                 <forward name="failure"
  11.                          path="payrollUploadJobStatus.do"
  12.                          redirect="false">
  13.                 </forward>
  14.         </action>
复制代码
jsp page
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <%@ page language="java" %>
  3. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  4. <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

  5. <HTML>


  6.         <HEAD>
  7.                 <meta http-equiv="refresh" content="5">
  8.                 <META name="GENERATOR" content="IBM WebSphere Studio">
  9.                 <TITLE>Payroll Upload Status</TITLE>
  10.                 <LINK href="addMaterial/ibas.css" type=text/css rel=stylesheet>
  11.         </HEAD>

  12.         <body bgcolor="#ffffff">
  13.        
  14.                 <img name="ibasMenu" src="images/remuneratorLogo.gif" width="760" height="55" border="0" usemap="#logo">

  15.                 <P>
  16.                 <P>
  17.                    <TABLE width="100%" border="0">
  18.                         <TR>
  19.                                 <TD align=center>
  20.                                         <FONT class="batchTxt">Please wait, Payroll Upload in progress.</FONT>
  21.                                 </TD>
  22.                         </TR>
  23.                         <TR>
  24.                                 <TD><P></TD>
  25.                         </TR>
  26.                         <TR>
  27.                                 <TD align=center>
  28.                                         <FONT class="mandatoryLabel">This page will automatically show the results of the upload, once it is complete.</FONT>
  29.                                 </TD>
  30.                         </TR>
  31.                 </TABLE>
  32.         </body>


  33. </HTML>
复制代码
请问,问什么上面的ACTION class 能持续的调用下面的jsp直到 满足pfBean != null && (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED
          || pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORT_FAILED ?
我晕啊!!!

[ 本帖最后由 lufumin1832 于 16-1-2010 00:43 编辑 ]
回复  

使用道具 举报

2#
 楼主| 发表于 15-1-2010 15:35:11 | 只看该作者
up up
回复  

使用道具 举报

3#
发表于 15-1-2010 15:39:02 | 只看该作者
注意看你的struts config,如果success,那么ACTION class 会forward到你写的jsp,如果失败,还是会forward到这个action,这个就是你说的“持续不断”

          <forward name="failure"
                         path="payrollUploadJobStatus.do"   <------这里指向的还是原来的action path="/payrollUploadJobStatus"
                         redirect="false">
                </forward>
回复  

使用道具 举报

4#
 楼主| 发表于 15-1-2010 22:18:35 | 只看该作者
原帖由 hoopoos 于 15-1-2010 16:39 发表
注意看你的struts config,如果success,那么ACTION class 会forward到你写的jsp,如果失败,还是会forward到这个action,这个就是你说的“持续不断”

           

一个女JAVA程序员也是向我这么解释的。可是下面的代码呢?
  1. else {
  2.                         forwardAction = Constants.ACTION_FAILURE;
  3.                        
  4.                         //use another object to avoid modifying orginal one
  5.                         ActionForward tempActionForward = new ActionForward();
  6.                         //Construct query string for forwardAction is success
  7.                         tempActionForward.setPath("/" + saveUrl);
  8.                         return (tempActionForward);
  9.                 }
复制代码
按我的理解这里不是返回了一个新的tempActionForward当条件不满足时候,  不是转到那个JSP page吗?
回复  

使用道具 举报

5#
 楼主| 发表于 15-1-2010 22:29:50 | 只看该作者
对了,我上面贴的是PayrollBatchJobStatus.jsp  不是struts congid里的那个jsp.

我对ACTION的流程理解是:
if (pfBean != null && (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED
          || pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORT_FAILED))
{
    forwardAction = Constants.ACTION_SUCCESS;
    也就是说应该转到sturts config 里的SUCESS也就是ClientPayrollImportResult.jsp 这个可以理解
}
else
{
    tempActionForward.setPath("/" + saveUrl);
                        return (tempActionForward);
  因为saveUrl ="PayrollBatchJobStatus.jsp"; 所以应该转到这个jsp 而这个jsp 才是那waiting page。 但是会怎么实现循环的呢?也就是反复查询这个ACTION??
}
回复  

使用道具 举报

6#
发表于 17-1-2010 19:59:02 | 只看该作者
你的forward是一次性的, PayrollBatchJobStatus.jsp是不会自动刷新.
回复  

使用道具 举报

7#
 楼主| 发表于 18-1-2010 08:00:17 | 只看该作者
原帖由 felix100 于 17-1-2010 20:59 发表
你的forward是一次性的, PayrollBatchJobStatus.jsp是不会自动刷新.

但是,事实上是会自动刷新的
回复  

使用道具 举报

8#
发表于 18-1-2010 11:09:27 | 只看该作者
我建议你把代码debug一下,就知道怎么回事了,step over 逐行,断点设在这个函数的第一行,public ActionForward securePerform
回复  

使用道具 举报

9#
发表于 18-1-2010 18:25:55 | 只看该作者
原帖由 lufumin1832 于 18-1-2010 09:00 发表

但是,事实上是会自动刷新的


从你的jsp,我看不出你的自动刷新,麻烦解释一下。
回复  

使用道具 举报

10#
 楼主| 发表于 19-1-2010 08:07:08 | 只看该作者
原帖由 felix100 于 18-1-2010 19:25 发表


从你的jsp,我看不出你的自动刷新,麻烦解释一下。

这就是我的问题啊!!!
我也是觉得jsp不会自动刷新的。
但是他确刷新了,显然是struts做一些magic。
我昨天debug也是一头雾水。我先做其他的工作,明天回头再看看
回复  

使用道具 举报

您需要登录后才可以回帖 登录 | FreeOZ用户注册

本版积分规则

小黑屋|手机版|Archiver|FreeOZ论坛

GMT+10, 3-5-2025 05:57 , Processed in 0.047967 second(s), 26 queries , Gzip On, Redis On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表