0

I have two applications (say ExternalAPP and InternalAPP) each has their own EAR in the same server, I'm using Struts 1.2. The idea is to call from InternalAPP one of ExternalAPP's jsp file and populate it with InternalAPP's information.

Since I cannot access ExternalAPP's ActionForm from InternalAPP, I create a similar form (InternalForm) and set it in the request attribute, then forward the action to ExternalAPP to setup it's action form called ExternalForm:

InternalAPP's code:

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's struts-config.xml

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

ExternalAPP's code:

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

I can get to the myDesiredPage.jsp from the InternalAPP just fine but it won't populate the information I sent on the request, all values will be empty.

What am I missing? I'm setting all values in ExternalAction in the action class before calling the JSP, why is it not picking them up?

If there's a better way to do it by all means please let me know, it seems to me that there should be a better way to do it.

Thanks in advance.

4

1 回答 1

0

我的错误是:

 ExternalForm  myForm = new ExternalForm();

而不是解析进入该方法的现有 ActionForm ......通过初始化它我重置了值,现在它可以工作了。

于 2015-11-04T18:00:09.720 回答