處理HTML5表單提交

上次更新: 2023-12-04
  • 建立對象:
  • Experienced
    Developer

HTML5表單可提交至AEM中託管的servlet。 提交資料可在servlet中作為輸入資料流存取。 若要提交HTML5表單,您必須使用AEM Forms Designer在表單範本上新增「HTTP提交按鈕」

建立您的提交處理常式

可以建立簡單的servlet來處理HTML5表單提交。 然後可以使用以下程式碼擷取提交的資料。 這個 servlet 在本教學課程中可供您使用。 請安裝 servlet 使用 封裝管理員

第9行的程式碼可用來叫用J2EE程式。 請確定您已設定 AdobeLiveCycle使用者端SDK設定 如果您要使用程式碼來叫用J2EE程式。

StringBuffer stringBuffer = new StringBuffer();
String line = null;
java.io.InputStreamReader isReader = new java.io.InputStreamReader(request.getInputStream(), "UTF-8");
java.io.BufferedReader reader = new java.io.BufferedReader(isReader);
while ((line = reader.readLine()) != null) {
    stringBuffer.append(line);
}
System.out.println("The submitted form data is " + stringBuffer.toString());
/*
        * java.util.Map params = new java.util.HashMap();
        * params.put("in",stringBuffer.toString());
        * com.adobe.livecycle.dsc.clientsdk.ServiceClientFactoryProvider scfp =
        * sling.getService(com.adobe.livecycle.dsc.clientsdk.
        * ServiceClientFactoryProvider.class);
        * com.adobe.idp.dsc.clientsdk.ServiceClientFactory serviceClientFactory =
        * scfp.getDefaultServiceClientFactory(); com.adobe.idp.dsc.InvocationRequest ir
        * = serviceClientFactory.createInvocationRequest("Test1/NewProcess1", "invoke",
        * params, true);
        * ir.setProperty(com.adobe.livecycle.dsc.clientsdk.InvocationProperties.
        * INVOKER_TYPE,com.adobe.livecycle.dsc.clientsdk.InvocationProperties.
        * INVOKER_TYPE_SYSTEM); com.adobe.idp.dsc.InvocationResponse response1 =
        * serviceClientFactory.getServiceClient().invoke(ir);
        * System.out.println("The response is "+response1.getInvocationId());
        */

設定HTML5表單的提交URL

submit-url

  • 點選xdp並按一下 屬性->進階
  • 複製http://localhost:4502/content/AemFormsSamples/handlehml5formsubmission.html ,並在「提交URL」文字欄位中貼上
  • 按一下 SaveAndClose 按鈕。

在排除路徑中新增專案

  • 瀏覽至 configMgr.
  • 搜尋 AdobeGranite CSRF篩選器
  • 在「排除的路徑」區段中新增下列專案
  • /content/AemFormsSamples/handlehml5formsubmission
  • 儲存您的變更

測試表單

  • 點選xdp範本。
  • 按一下 預覽->以HTML預覽
  • 在表單中輸入一些資料,然後按一下提交
  • 您應該會看到提交的資料已寫入伺服器的stdout.log檔案

其他閱讀

這個 文章 建議從HTML5表單提交產生PDF時一併執行。

此頁面上的