Struts2 (1) --- struts2 environment establishment and instance

Source: Internet
Author: User

Struts2 (1) --- struts2 environment establishment and instance

I have just been familiar with struts2, but I am a little confused. I am still used to writing code first, and then gradually understand the ideas.
This article mainly describes how to use struts to simplify programming by setting up the strusts environment and using a simple example.

1. The project structure is as follows, including required packages.

2. web. xml


  
    
      
     
           
    
     
Struts2
           
            
    
     
Org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter
        
       
       
           
    
     
Struts2
            
    
     
/*
        
     
       
    
     
Index. jsp
      
   
  

3. struts. xml


  
      
       
       
       
                          
    
     
/Welcome. jsp
                 
    
     
/Login.html
                                   
    
     
/Login.html
                 
   
  

4. LoginAction. java

Package action; import com. opensymphony. xwork2.ActionSupport; // This class inherits the ActionSupport class. In this way, you can directly use variables such as SUCCESS and LOGIN and the public class LoginAction extends ActionSupport {private String name; private String password; public String getName () {return name ;} public void setName (String name) {this. name = name;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;}/*** return value here use the custom * @ return */public String index () {return index ;} /*** the return value directly uses variables such as SUCCESS */public String execute () {// The value if (sa. equals (name) & aaaaaa. equals (password) return SUCCESS; return LOGIN ;}}

6.login.html

7.welcome.html

<%@ page language=java import=java.util.* pageEncoding=ISO-8859-1%><%String path = request.getContextPath();String basePath = request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%>
> welcome!!!

After tomcat is started, enter http: // localhost: 8080/struts2/index in the address bar to open login.html.
Enter sa and aaaaaa to open welcome. jsp.

 

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.