First, Introduction
To develop a Web application, you should first encounter the receipt of user input data, which is a traditional Web application called HttpServletRequest's GetParameter (Stringname) method to fetch data from the request. The web framework provides a data binding mechanism by which the framework obtains data from the request and binds it to a JavaBean object.
STRUTS2 provides a variety of ways to receive user input data.
Struts2 's action is completely decoupled from the web, and to get the data for the Web tier, you need to use Actioncontext, which provides an execution context for the action.
The action receives the user data each way
A, receive data mode one: Use domain object to receive user input
One of the drawbacks of STRUTS1 is that Struts1 uses Actionform to receive data entered by the user. In Struts2, it is supported to use domain objects directly to receive data entered by the user.
Example Login.jsp
writing the user class
writing the Loginaction class
Struts.xml
For illustrative purposes
B, receive data mode two: Use Modeldrivenaction
Loginaction class
page login.jsp
C, receive data mode three: Use the Action property to receive user input
Other parts do not need to be changed.
STRUTS2 Beginner Struts2 Action receive user data mode