Login. jsp -->
LoginAction. java --->
Public class LoginAction extends Action {
// We need to re-compile a method: execute will be automatically called, a bit similar to the service method in servlet
@ Override
Public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
Throws Exception {
// Convert form to the corresponding UserForm object
UserForm userForm = (UserForm) form;
System. out. println ("username -->" + userForm. getUsername ());
System. out. println ("password -->" + userForm. getPassword ());
Request. setAttribute ("username", userForm. getUsername ());
If ("123". equals (userForm. getPassword ())){
Return mapping. findForward ("OK ");
} Else {
Return mapping. findForward ("err ");
}
}
}
UserForm. java --->
Package com. cb. forms;
// This is a user form for filling in Data
Import org. apache. struts. action. ActionForm;
// Inherit a superclass ActionForm
Public class UserForm extends ActionForm {
// Define attributes [There is a specification here, that is, when we define the attribute name,
// It should be the same as the jsp page space name]
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;
}
}
Struts-config.xml --->
Web. xml ----->
Action
Org. apache. struts. action. ActionServlet
Config
/WEB-INF/struts-config.xml
This is the description of my J2EE component
This is the display name of my J2EE component
Test
Test
Action
*. Do
Test
/Servlet/test
Index. jsp
Zookeeper