2015-11-03 19 views
0

我有兩個應用程序(比如說ExternalAPP和InternalAPP)在同一個服務器上都有自己的EAR,我使用的是Struts 1.2。這個想法是從InternalAPP調用ExternalAPP的一個jsp文件並用InternalAPP的信息填充它。當外部動作來自struts動作表單不顯示

既然不能訪問從InternalAPP ExternalAPP的ActionForm中,我創建了一個類似的形式(InternalForm),並設置它在請求屬性,那麼行動ExternalAPP轉發設置,它被稱爲ExternalForm動作形式:

InternalAPP的代碼:

public final String process(HttpServletRequest request, ActionForm form) 
      throws Exception { 
    ... 
    InternalForm myForm = new InternalForm(); 
    myForm.setTo("[email protected]"); 
    myForm.setFrom("[email protected]"); 

    //pass this form to the next action in json form 
    ObjectMapper mapper = new ObjectMapper(); 
    String myFormToJson = mapper.writeValueAsString(myForm); 

    request.setAttribute("myForm", myFormToJson); 

    return "forwardExternalAction"; 
} 

InternalAPP的struts-config.xml中

<global-forwards> 
    .... 
    <forward name="forwardExternalAction" path="/forward/path/externalFormInit.do"/> 
</global-forwards> 

ExternalAPP代碼:

<action path="/path/externalFormInit" type="com.action.ParseFormAction" > 
    <forward name="success" path="/externalAction.do" /> 
</action> 

<action path="/externalAction" 
    type="org.apache.struts.actions.ForwardAction" 
    name="ExternalForm" 
    validate="false" 
    scope="request" 
    input="/task/myDesiredPage.jsp"> 
    <forward name="success" path="/task/myDesiredPage.jsp" /> 
     <forward name="error" path="/task/myDesiredPage.jsp" /> 
</action> 

ParseFormAction.java

public ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest request, 
    HttpServletResponse response) throws Exception { 

    JSONObject jsonObj = new JSONObject((String) request.getAttribute("myForm")); 
    ExternalForm myForm = new ExternalForm(); 
    myForm.setTo(jsonObj.getString("to")); 
    myForm.setFrom(jsonObj.getString("from")); 

    request.setAttribute("ExternalForm", myForm); 

    return mapping.findForward("success"); 
} 

myDesiredPage.jsp

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 

<html> 
....  
       <html:form action="/path/sendOutForm.do" method="POST" > 

        <div class="form-body"> 
         <div class="frm-row"> 

          <div class="colm6"> 

           <div class="section"> 
            <label class="field prepend-icon"> 
             <html:text property="from" styleClass="gui-input" styleId="fromStyle" disabled="true" /> 
             <span class="field-icon"><i class="fa fa-envelope"></i></span> 
            </label> 
           </div><!-- end section --> 

           <div class="section"> 
            <label class="field prepend-icon"> 
             <html:text property="to" styleClass="gui-input" styleId="toStyle" /> 
             <span class="field-icon"><i class="fa fa-envelope"></i></span> 
            </label> 
           </div><!-- end section --> 
          </div><!-- end .colm6 section --> 

         </div><!-- end .frm-row section -->        
      </html:form> 
...  
</html> 

我能到myDesiredPage.jsp從InternalAPP得很好,但它不會填充我發送的信息根據請求,所有值都將爲空。

我錯過了什麼?在調用JSP之前,我在動作類中設置了ExternalAction中的所有值,爲什麼它沒有選擇它們?

如果還有更好的方法來做到這一點,請讓我知道,在我看來,應該有更好的方式來做到這一點。

在此先感謝。

回答

0

我的錯誤是在:

ExternalForm myForm = new ExternalForm(); 

而是通過初始化它,我重置值分析現有的ActionForm進入的方法......,如今它的工作原理。

相關問題