Entry Struts case

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.