2013年9月17日星期二

struts2 is how to get the browser with parameters ? ! !

Browser address bar :
http://localhost:8080/Struts2/test/l_execute2.do?name=dzr&id=121212


struts.xml configuration page
<action name="l_*" class="cn.dzr.action.HelloWorldAction" method="{1}">
  <result name="success">/WEB-INF/page/hello.jsp</result>
  </action>


JSP pages :
<body>

<h2>name=${name }</h2>
<h2>id=${id }</h2>
</body>
</html>



Action page :
	private int id;
private String name;

public int getId()
{
return id;
}

public void setId(int id)
{
this.id = id;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}
//......

       public String execute2()
{
return "success";
}



results when running , the page displays the parameters passed . But is not clear , what is at what time, parameters are passed into the action.



------ Solution ------------------------------------ --------
know the main floor, it would have to go to the source struts2 it. Have read the struts2 source, said the whole process a bit long, you can tell the landlord will request in struts2 parameters are placed into the value he created stack (ValueStack) in , action was created in the Dispatcher serviceAction methods ( implementation of the corresponding action) is created primarily by creating a class ContainerImpl class is responsible for , it will be configured according to your xml object factory to create, if configured to use spring spring plants to create the default xwork object factory to create, assignment it will go through the appropriate type converter , this process is earlier than interceptors .

没有评论:

发表评论