Struts2 Development Environment Construction

Source: Internet
Author: User

I. Development Environment

Eclipse, tomcat, and struts-2.2.3

Eclipse: http://www.eclipse.org/downloads/ tomcat: http://tomcat.apache.org/download-70.cgi struts: http://struts.apache.org/download.cgi#struts23162
2. Create a web project and add the dependent jar package to the web project.

3. Configure web. xm and configure the Struts2 filter to web. xml
 
      
  
   
    struts2
      
   
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter   
      
    
       
   
    struts2
       
   
    /*
     
    
      
   
    index.jsp
     
  
 

As the core controller of the Struts2 framework, FilterDispather intercepts all user requests. When a user request arrives, the filter filters user requests so that different requests are divided by service type, the request is sent to different business controllers. Action calls different business models to process the request and returns the processing result to the view.
4. Create an Action business controller for a web project
package Action; import com.opensymphony.xwork2.ActionSupport; public class indexAction extends ActionSupport {    public String index()    {        return SUCCESS;    }}

Action is a part of C in MVC. It is used to call a method of a java class for data preprocessing and related business logic processing, and then return the final processing result, the result can be a page with or without parameters to access other services or links. or do nothing.
5. Configure Struts. xml and configure the Action Service controller to Struts. xml.
  
 
       
                      
   
                    /hello.jsp            
                
      
  
 

Why do we need to configure struts. xml? In addition to the MVC Framework, Struts2 is also a small and lightweight container that manages the core controller FilterDispather and business controller Action. it can be said that the struts container forwards the user requests intercepted by the core controller to the service controller, instead of directly forwarding the requests to the service controller, this removes the coupling between the core controller FilterDispather and the Business controller Action. The core controller FilterDispather is only responsible for intercepting user requests and the Business controller is only responsible for processing business requests, the core controller and the Business controller communicate with each other through the struts container, and they do not know each other.
6. Add a jsp View
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>            My JSP 'index.jsp' starting page    
     
     
        
     
     
          

7. Deploy the project to Tomcat. Open the browser and enter http: // localhost: 8080/Project1/index. The hello word page is displayed. The configuration is successful.

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.