1. the jsp sends a value to the action. The jsp sends the value to the action.
1. form submission method
2. href Method
"> Delete
Ii. Pass a value to the action in jsp. method accepted by the action
1. Define form attributes in the Action class. The two attributes must have the same name. Provides the setter and getter methods. You can receive the parameter. private String username passed in the form;
Private String password;
Public String getUsername (){
Return username;
}
Public void setUsername (String username ){
This. username = username;
}
Public String getPassword (){
Return password;
}
Public void setPassword (String password ){
This. password = password;
}
2. encapsulate the parameters passed in the form into a class, and then call the attributes. For example, encapsulate the parameters to be sent from the login. jsp page (for example, encapsulated in the Users class)
Private String username;
Private String password;
Public String getUsername (){
Return username;
}
Public void setUsername (String username ){
This. username = username;
}
Public String getPassword (){
Return password;
}
Public void setPassword (String password ){
This. password = password;
}
Then define the object of the class in the Action method, as shown in figure
Public class loginAction extends ActionSupport {
Private Users users;
Public Users getUsers (){
Return users;
}
Public void setUsers (Users users ){
This. users = users;
}
}
To pass the value through this method, you must also perform some processing on the jsp page. The from1 attribute name in login. jsp should be changed to this:
Login form login. jsp:
This method is a common method in struts development!
3. Implement the ModelDriven interface to receive form data
First, the Action class must implement the ModelDriven interface and encapsulate the data transmitted from the form. The Action class must instantiate the object and override the getModel () method.
Public class loginAction extends ActionSupport implementsModelDriven {
Private Users users = new Users ();
Public Users getModel (){
Return users;
}
} 3. The action is returned to jsp. jsp accepts method 1. In the Action, you can call the setAttirbute method of the session or request object, and then retrieve it from jsp. In the java source file of action, write ActionContext ac = ActionContext. getContext ();
Map session = ac. getSession ();
Session. put ("currentUser", user); On the jsp page, you can access the user User user = (User) session through the session. getAttribute ("currentUser"); 2. OGNL (