struts problem 2( hoopoos 请进谢谢)
public class PayrollUploadJobStatusAction extends SecureAction{
Properties props = new Properties();
/**
* @see SecureAction#securePerform(ActionMapping, ActionForm, ActionContext, HttpServletRequest, HttpServletResponse)
*/
public ActionForward securePerform(ActionMapping mapping,
ActionForm form,
ActionContext actionContext,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String forwardAction = Constants.ACTION_SUCCESS;
getErrors(request);
String saveUrl ="PayrollBatchJobStatus.jsp";
//Check the status of importing
String payrollFileId = request.getParameter("payrollFileId");
PayrollFileBean pfBean = PayrollFileDao.retrieveByPayrollFileId(actionContext.getConnection(), (new Integer(payrollFileId)).intValue());
if (pfBean != null && (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED
|| pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORT_FAILED)) {
forwardAction = Constants.ACTION_SUCCESS;
ClientPayrollUploadJobStatusForm statusForm = new ClientPayrollUploadJobStatusForm();
if (form != null)
statusForm = (ClientPayrollUploadJobStatusForm)form;
if (pfBean.getStatus() == Constants.IMPORT_STATUS_IMPORTED)
statusForm.setAction(Constants.ACTION_SUCCESS);
else
statusForm.setAction(Constants.ACTION_FAILURE);
List logs = IbasLogDao.retrieveByBatchId(actionContext.getConnection(), pfBean.getImportBatchId());
Iterator it = logs.iterator();
List msgList = new ArrayList();
while (it.hasNext()) {
com.rem.ibas.model.bean.IbasLogBean logBean = (com.rem.ibas.model.bean.IbasLogBean)it.next();
msgList.add(logBean.getDescription());
}
//statusForm.setOriginalMessage(msg);
statusForm.setPayrollFileId(pfBean.getPayrollFileId().toString());
request.setAttribute("msgList", msgList);
}
else {
forwardAction = Constants.ACTION_FAILURE;
//use another object to avoid modifying orginal one
ActionForward tempActionForward = new ActionForward();
//Construct query string for forwardAction is success
tempActionForward.setPath("/" + saveUrl);
return (tempActionForward);
}
return (mapping.findForward(forwardAction));
}
}Struts config<action path="/payrollUploadJobStatus"
type="com.rem.ibas.model.action.PayrollUploadJobStatusAction"
name="ClientPayrollUploadJobStatusForm"
validate="false"
scope="request">
<forward name="success"
path="/ClientPayrollImportResult.jsp"
redirect="false">
</forward>
<forward name="failure"
path="payrollUploadJobStatus.do"
redirect="false">
</forward>
</action>jsp page<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<HTML>
<HEAD>
<meta http-equiv="refresh" content="5">
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>Payroll Upload Status</TITLE>
<LINK href="addMaterial/ibas.css" type=text/css rel=stylesheet>
</HEAD>
<body bgcolor="#ffffff">
<img name="ibasMenu" src="images/remuneratorLogo.gif" width="760" height="55" border="0" usemap="#logo">
<P>
<P>
<TABLE width="100%" border="0">
<TR>
<TD align=center>
<FONT class="batchTxt">Please wait, Payroll Upload in progress.</FONT>
</TD>
</TR>
<TR>
<TD><P></TD>
</TR>
<TR>
<TD align=center>
<FONT class="mandatoryLabel">This page will automatically show the results of the upload, once it is complete.</FONT>
</TD>
</TR>
</TABLE>
</body>
</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 编辑 ] up up :'( :'( 注意看你的struts config,如果success,那么ACTION class 会forward到你写的jsp,如果失败,还是会forward到这个action,这个就是你说的“持续不断”
<forward name="failure"
path="payrollUploadJobStatus.do" <------这里指向的还是原来的action path="/payrollUploadJobStatus"
redirect="false">
</forward> 原帖由 hoopoos 于 15-1-2010 16:39 发表 http://www.freeoz.org/bbs/images/common/back.gif
注意看你的struts config,如果success,那么ACTION class 会forward到你写的jsp,如果失败,还是会forward到这个action,这个就是你说的“持续不断”
一个女JAVA程序员也是向我这么解释的。可是下面的代码呢?else {
forwardAction = Constants.ACTION_FAILURE;
//use another object to avoid modifying orginal one
ActionForward tempActionForward = new ActionForward();
//Construct query string for forwardAction is success
tempActionForward.setPath("/" + saveUrl);
return (tempActionForward);
}按我的理解这里不是返回了一个新的tempActionForward当条件不满足时候,不是转到那个JSP page吗?
:'( :'( :'( 对了,我上面贴的是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??
} 你的forward是一次性的, PayrollBatchJobStatus.jsp是不会自动刷新. 原帖由 felix100 于 17-1-2010 20:59 发表 http://www.freeoz.org/bbs/images/common/back.gif
你的forward是一次性的, PayrollBatchJobStatus.jsp是不会自动刷新.
但是,事实上是会自动刷新的:L :L 我建议你把代码debug一下,就知道怎么回事了,step over 逐行,断点设在这个函数的第一行,public ActionForward securePerform 原帖由 lufumin1832 于 18-1-2010 09:00 发表 http://www.freeoz.org/bbs/images/common/back.gif
但是,事实上是会自动刷新的:L :L
从你的jsp,我看不出你的自动刷新,麻烦解释一下。 原帖由 felix100 于 18-1-2010 19:25 发表 http://www.freeoz.org/bbs/images/common/back.gif
从你的jsp,我看不出你的自动刷新,麻烦解释一下。
这就是我的问题啊!!!
我也是觉得jsp不会自动刷新的。
但是他确刷新了,显然是struts做一些magic。
我昨天debug也是一头雾水。我先做其他的工作,明天回头再看看
页:
[1]