0

I need to invoke the href link on my java method. My sample code is defined below. After finishing my logic i need to invoke the URL. The URL is used to open an Excel workbook and import our bean values to there.

public void populateExcelReportValues(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        String METHOD_NAME = "populateExcelReportValues";
        log.entering(CLASS_NAME, METHOD_NAME);

        //Rating Element Id 
        String ratingElementIdForExcel = request.getParameter("ratingElementIdFromJSP");
        //Instance Type Name
        String instanceTypeForExcel = request.getParameter("instanceTypeFromJSP");
        int ratingElementIdForExcelInt = 0;

        String instanceTypeValueForExcel = "";
        if(ratingElementIdForExcel != null && ratingElementIdForExcel.trim().length()>0)
        {
            ratingElementIdForExcelInt = Integer.parseInt(ratingElementIdForExcel);
            System.out.println("ratingElementIdForExcelInt: "+ratingElementIdForExcelInt);

        }
        if(instanceTypeForExcel != null && instanceTypeForExcel.trim().length()>0)
        {
            instanceTypeValueForExcel = instanceTypeForExcel.trim();
            System.out.println("instanceTypeValueForExcel: "+instanceTypeValueForExcel);
        }
        switch (ratingElementIdForExcelInt) 
        {
            case 1: //ASN Accuracy - Rating Element ID - 1 
                    weeklyDeliveryInstancesRatingElementQO = getASNAccuracyRatingElement(instanceTypeValueForExcel);
                    //return weeklyDeliveryInstancesRatingElementQO;
                    break;
            default:
                    weeklyDeliveryInstancesRatingElementQO = new ArrayList<WeeklyDeliveryInstancesRatingElementQO>();
                    break;
        }
        //How to invoke this url to here
        **(MultiTableExportServlet?multitablesId=WeeklyDeliveryInstances-Count&amp;name=WeeklyDeliveryInstances-Count&amp;type=excel)**
        log.exiting(CLASS_NAME, METHOD_NAME);
    }

In above my code i showed to bold for your identification.

Jsp page:

<display:table name="${weeklyDlvyInstancesDashboardReportForm.asnAccuracyListQO}" uid="asnAccuracyListUID" sort="list" defaultsort="1" 
                                        requestURI="/weeklyDlvyInstancesDashboardReportPre.do?method=httpGet" excludedParams="method"
                                        decorator="com.ford.mpl.superg.decorator.WeeklyDeliveryInstancesTypeTableDecorator" keepStatus="true">
                                        <%@include file="/jsp/include/displaytag.jsp"%>
                                        <c:set value="${asnAccuracyListUID.firstWeekOfCountLabel}" var="asnAccuracyFirstWeekOfCount"/>
                                        <c:set value="${asnAccuracyListUID.secondWeekOfCountLabel}" var="asnAccuracySecondWeekOfCount"/>
                                        <c:set value="${asnAccuracyListUID.thirdWeekOfCountLabel}" var="asnAccuracyThirdWeekOfCount"/>
                                        <c:set value="${asnAccuracyListUID.fourthWeekOfCountLabel}" var="asnAccuracyFourthWeekOfCount"/>
                                        <c:set value="${asnAccuracyListUID.fifthWeekOfCountLabel}" var="asnAccuracyFifthWeekOfCount"/>
                                        <c:set value="${asnAccuracyListUID.sixthWeekOfCountLabel}" var="asnAccuracySixthWeekOfCount"/>

                                        <c:choose>
                                        <c:when test="${asnAccuracyListUID.instanceTypeDescription != null && asnAccuracyListUID.instanceTypeDescription != 'Sum'}">
                                            <display:column property="instanceTypeDescription" title="Instance Type" sortable="false"/>
                                        </c:when>
                                        <c:otherwise>
                                            <display:column property="instanceTypeDescription" title="Instance Type" sortable="false" style="font-weight:bold;text-align:center"/>
                                        </c:otherwise>
                                        </c:choose>


                                        <display:column property="firstWeekOfCount" title="${asnAccuracyFirstWeekOfCount}" sortable="false"/>
                                        <display:column property="secondWeekOfCount" title="${asnAccuracySecondWeekOfCount}" sortable="false"  />
                                        <display:column property="thirdWeekOfCount" title="${asnAccuracyThirdWeekOfCount}" sortable="false"  />
                                        <display:column property="fourthWeekOfCount" title="${asnAccuracyFourthWeekOfCount}" sortable="false" />
                                        <display:column property="fifthWeekOfCount" title="${asnAccuracyFifthWeekOfCount}" sortable="false" />
                                        <display:column property="sixthWeekOfCount" title="${asnAccuracySixthWeekOfCount}" sortable="false"/>
                                    </display:table>
                                </fieldset>

                                <export:multitables id="WeeklyDeliveryInstances-Count">
                                        <export:table title="tablename" source="${weeklyDlvyInstancesDashboardReportForm.weeklyDeliveryInstancesRatingElementQO}">
                                            <export:column property="shipCode" title="Ship Code" />
                                            <export:column property="plantOrRecLoc" title="Plant/Rec Loc" />
                                            <export:column property="instanceType" title="Instance Type" />
                                            <export:column property="fordOrg" title="Ford Org" />
                                            <export:column property="OrgType" title="Org Type" />
                                            <export:column property="region" title="Region" />
                                            <export:column property="shipDate" title="Ship Date" />
                                            <export:column property="errorTransmitted" title="Error Transmitted" />
                                            <export:column property="externalAlertNo" title="External Alert Number" />
                                            <export:column property="asnNumber" title="ASN Number"/>
                                            <export:column property="packingSlipNumber" title="Packing Slip Number"/>
                                        </export:table>
                                    </export:multitables>
4

1 回答 1

0

我会采取这种方法:

在 struts-config.xml 中为您的操作中的 servlet 添加转发,例如:

<forward name="Success" path="/servlet/MultiTableExportServlet"/>

(如果与上面不同,您需要将“路径”更改为 servlet 的 url 模式)。

在您的 Action 类中,您可以通过执行以下操作重定向到此转发:

    ActionForward originalForward = a_mapping.findForward ("Success");  
    String path = originalForward.getPath() 
        + "?multitablesId=WeeklyDeliveryInstances-Count&name=WeeklyDeliveryInstances-Count&type=excel";     

    ActionForward forward = new ActionForward(path);
    forward.setRedirect(true);
    return (forward);

您的查询字符串(multitablesId=WeeklyDeliveryInstances-Count 等)看起来错误。WeeklyDeliveryInstances-Count 是变量吗?我看不到您在哪里定义或使用它。

于 2012-10-18T09:49:33.233 回答