You are here
Home > Programming > Java > Struts2 > Tutorial Action Chaining Apache Struts2

Tutorial Action Chaining Apache Struts2

Tutorial Action Chaining Apache Struts2

Kita lanjutkan belajar struts2 dengan judul Tutorial Action Chaining Apache Struts2. Mari kita lihat apa itu Action Chaining

The framework provides the ability to chain multiple actions into a defined sequence or workflow. This feature works by applying a Chain Result to a given Action, and intercepting its target Action’s invocation with a Chaining Interceptor.
“As a rule, Action Chaining is not recommended. First explore other options, such as the Redirect After Post technique.”
sumber: apache

Sekarang ayo kita mulai Tutorial Action Chaining Apache Struts2:

  • Buka folder workspace anda, jangan lupa pelajari dulu Tutorial Basic Apache Struts2. Karena kita akan melanjutkan source codenya.
  • Buat folder “action-chaining-struts2” di workspace anda
  • Copy file “pom.xml” dan folder “src” di folder “basic-struts2” tutorial sebelumnya.
  • Buka file “pom.xml”, rubah artifact-id “basic-struts2” ke “action-chaining-struts2”
  • Rubah juga tag name dan description “Belajar Action Chaining Struts2”
  • Buka IDE eclipse
  • Pilih import >> existing maven project >> browse ke folder “action-chaining-struts2” >> finish
  • Project baru action-chaining-struts2 sudah berhasil di load

Mari kita mulai melakukan perubahan selanjutnya

  • Create package “com.wijaksana.belajar.struts2.action”
  • Tambahkan class sebagai controller/action dengan nama “ActionA” di package “com.wijaksana.belajar.struts2.action” dan tambah extend “ActionSupport”
  • Tambahkan properti “name” dan setting getter/setter-nya
  • Tambahkan @Override method “execute”
  • Tambahkan script dibawah ini pada method “execute”
  • Tambahkan class sebagai controller/action dengan nama “ActionB” di package “com.wijaksana.belajar.struts2.action” dan tambah extend “ActionSupport”
  • Tambahkan properti “name” dan setting getter/setter-nya
  • Tambahkan @Override method “execute”
  • Tambahkan script dibawah ini pada method “execute”
  • Buka file struts.xml (src/main/resources), replace script didalam tag <struts> dengan script dibawah ini
  • Tambahkan file index.jsp (src/main/webapp/WEB-INF), replace semua script dengan script dibawah ini:
  • Tambahkan file ActionB.jsp (src/main/webapp/WEB-INF), replace semua script dengan script dibawah ini:
  • Selesai, bisa kita test sekarang
  • Caranya masih ingatkan untuk menjalankan programnya? iya bener, Klik kanan project name >> Run As >> Maven Build… >> pada isian goals ketik “jetty:run” >> klik RUN
  • Buka browser http://localhost:8080

Selamat mencoba,

 

salam berbagi,
wijaksana

Leave a Reply