提交最適化表單至外部伺服器 submitting-adaptive-form-to-external-server

使用「提交至REST端點」動作,將提交的資料發佈至REST URL。 該 URL 可以是內部伺服器 (呈現表單的伺服器) 或外部伺服器。

通常客戶會想要將表單資料提交至外部伺服器,以便進一步處理。

若要將資料發佈到內部伺服器,請提供資源的路徑。 資料會發佈到資源的路徑。例如, </content restendpoint=""> . 對於此類發佈請求,會使用提交請求的驗證資訊。

若要將資料發佈到外部伺服器,請提供 URL。URL 的格式是:http://host:port/path_to_rest_end_point。確保您已設定匿名處理POST請求的路徑。

為了撰寫本文的目的,我撰寫了一個簡單的war檔案,可部署在您的tomcat執行個體上。 假設您的tomcat正在連線埠8080上執行,則POSTURL將為

http://localhost:8080/AemFormsEnablement/HandleFormSubmission

當您設定最適化表單以提交至此端點時,表單資料和附件(如有)可透過以下程式碼擷取到servlet中

System.out.println("form was submitted");
Part attachment = request.getPart("attachments");
if(attachment!=null)
{
    System.out.println("The content type of the attachment added is "+attachment.getContentType());
}
Enumeration<String> params = request.getParameterNames();
while(params.hasMoreElements())
{
String paramName = params.nextElement();
System.out.println("The param Name is "+paramName);
String data = request.getParameter(paramName);System.out.println("The data  is "+data);
}

表單提交
若要在您的伺服器上測試此專案,請執行下列動作

  1. 請安裝Tomcat (如果尚未安裝)。 此處提供安裝tomcat的說明
  2. 下載 zip檔案 與此文章相關聯。 解壓縮檔案以取得war檔案。
  3. 在您的tomcat伺服器中部署war檔案。
  4. 建立具有檔案附件元件的簡單調適型表單,並設定其提交動作,如上方熒幕擷圖所示。 POSTURL為 http://localhost:8080/AemFormsEnablement/HandleFormSubmission. 如果您的AEM和tomcat未在localhost上執行,請適當的變更URL。
  5. 若要啟用將多部分表單資料提交至tomcat的功能,請將下列屬性新增至 <tomcatinstalldir>\conf\context.xml並重新啟動Tomcat伺服器。
  6. <Context allowCasualMultipartParsing="true">
  7. 預覽最適化表單、新增附件並提交。 檢查tomcat主控台視窗中的訊息。
recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e