At a high level, how does struts2 work? I am coming from mvc background

At a high level, how does struts2 work? I am coming from mvc background

After looking at the project example, I see that these are ___action class classes.

Is this just a reference to a controller action? i.e. a response to a specific get / post based url?

+3
source share
2 answers

Typical Struts2 workflow (remember that Struts2 is extremely customizable, its parts are well decoupled)

struts.xml => defines 'mappings':

  • which actionruns for each URL
  • one or more results: which resource (usually a JSP) generates a view for each result returned by the action

, , , a struts.xml

   <action name="add" class="example.SumAction">
     <result name="error">/Error.jsp</result>
     <result name="success">/SumResult.jsp</result>
   </action>

Java:

   public class SumAction { 
       private int x;
       private int x;
       private int z;
       // getters and setters ommited
       public String execute() {
           z = x + y; 
           return "success";
       }
   }

http://mysite.com/mywebapp/add.action?x=10&y=20 Struts2 SumAction, x y execute. "" , "", "/SumResult.jsp", struts2, , .

 Result: <b><s:property value="z" /></b>

, execute() .

, , +, , , , ( ). .

+4

, - . URL-, , , -, " " " jsp".

jsps - . , RIA, xhrs json, V MVC - extjs -, .

Struts VC, . . struts, .

0

Source: https://habr.com/ru/post/1755016/


All Articles