Struts 2 what is inside

Friday, March 2, 2012 Posted by Sanka Senevirathna 0 comments
Today I am write about struts 2.Struts 1 is failed and complex.Developer have to implement so many unnecessary methods. But in struts 2 it also introduce POJO concept.

I will point out some key points.
Struts 2=Struts 1 + Web Works Framework
Struts 2 Action classes are POJOs
Struts 2 introduce ActionSupport class.
ActionSupport=Action class+ Form Bean


Suppose you are submiting a html form.Then in java request go to web xml.After that web xml apply its filters and find filter class of struts framework called 'FilterDispatcher'.Ok now request is in struts framwork.In here action property of html form is the key and now struts search value of given action key from struts.xml file.

 So it search name attribute of action tag. If it found then get the class attribute and forword the request to action class.
 execute is the first method that execute in Action class.After that execute method return some key that indicate where to go.
 Then again use the struts.xml and find the nested  result tags of paticular action class and get the value and redirect it into that page.
 /success.jsp











In Java web every request go through the web.xml.



Then web.xml redirect the request to struts 2 FilterDispatcher class and after that struts 2 determine which request goto which action class by using struts.xml


Struts Action class is POJO. That mean no more implement interface,extends library class





Following is the sequence of execution of struts 2.

struts  2 සිංහලෙන්  Sinhala Translation 


ඇත්තටම struts  2    framework එකේ වෙන්නේ මොකද්ද කියන එක අද මම සාකච්චා කරන්න හදන්නේ.මුලින්ම හිතන්න අපි html form 1ක් submit කරනවා කියල. Java web වලදී   මේ request එක යනවා web .xml file එකට. එකේ තියෙන FilterDispatcher කියන class එකට  තමා  යන්නේ.  FilterDispatcher කියන්නේ   struts  2 framework එකේ තියෙන class එකක්.  මෙතනට ගියාම ඉතින් request එක  struts2 වලට ගියා කියල හිතන්නකෝ.  දැන්  struts  2 framework එකේ වෙන්නේ මොකද්ද ?
 එය හොයනවා form එකේ action එකට ගැලපෙන value එකක් struts .xml එකේ හොයනවා.
 .test.SampleAct">
 ඉතින් මෙයා හොයන්නේ name කියන property  එකට අදාල value එක තමා.  මෙතන හැටියට නම්  SampleAct තමා key එක.class එක com.codexamples.test.SampleAct තමා value එක. ඉතින් ඊට පස්සේ අර request එක redirect කරනවා   com.codexamples.test.SampleAct කියන action class එකට. Action class එකේ තියන වැදගත් සිද්ඩිය තමා මේකේ මුලින්ම excecute වෙන්නේ  excecute කියන method එක. ඉතින් ඒයා (excecute කියන method එක) return karana value එක තියනවනේ("SUCCESS") එකත් ආයේ    නිකම් value එකක් නෙවේ. එකෙන් ලොකු දෙයක් කියවෙනවා එක තමා මෙතොඩ් එක execute
වෙලා ඉවර වෙලා කොහෙටද redirect වෙන්නේ කියල.
/success.jsp
එක short code එකක්.key එකක්. Action tag එක ඇතුලේ nested tag එකක් තියෙනෙව result කියල. ඔන්න ඔකේ key එක තමා ඔතන return කරන්නේ. ඉතින් එතකොට එකේ value එක හොයාගෙන ඒ page එකට redirect කරන එක තමා සිද්දවෙන්නේ ඉතින්.                                                               
Labels: