0

2 つのアプリケーション (ExternalAPP と InternalAPP など) があり、それぞれが同じサーバーに独自の EAR を持っています。Struts 1.2 を使用しています。アイデアは、InternalAPP から ExternalAPP の jsp ファイルの 1 つを呼び出し、InternalAPP の情報を入力することです。

InternalAPP から ExternalAPP の ActionForm にアクセスできないため、同様のフォーム (InternalForm) を作成して request 属性に設定し、アクションを ExternalAPP に転送して、ExternalForm というアクション フォームをセットアップします。

InternalAPP のコード:

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

    //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> 

InternalAPP から myDesiredPage.jsp に問題なくアクセスできますが、リクエストで送信した情報が入力されず、すべての値が空になります。

私は何が欠けていますか?JSP を呼び出す前に、アクション クラスの ExternalAction ですべての値を設定していますが、なぜ値が取得されないのですか?

どうしてもいい方法があれば教えてください。もっといい方法があるはずだと私には思えます。

前もって感謝します。

4

1 に答える 1

0

私のエラーはオンでした:

 ExternalForm  myForm = new ExternalForm();

メソッドに入ってくる既存のActionFormを解析する代わりに...初期化することで値をリセットしましたが、今では機能します。

于 2015-11-04T18:00:09.720 に答える