Struts-2.3

Source: Internet
Author: User

Preface

This document describes how to use Tomcat as the j2ee container and Sqlserver2005 as the database. Struts version 2.3.15.3

Struts Introduction

Struts is an open-source project sponsored by the Apache Software Foundation (ASF. Struts is an open-source software. The purpose of Struts is to help us reduce the time needed to develop Web applications using MVC design models. Struts is a good choice if we want to use the advantages of Servlets and JSP together to build scalable applications.

Obtain Struts

Go to the Struts Official Website: http://struts.apache.org /. Click Dwonload and select a version suitable for Struts download.

Download struts-2.3.15.3-all.zip and get the following structure directory:

Create StrutsDemo and introduce lib package

Create a web project StrutsDemo in Myeclipse, and import the following content from the downloaded Struts lib package:

Go to the project lib directory.

Web. xml configuration

Edit web. xml and add the following code to web. xml:

         
  
   struts2
          
  
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      
      
         
  
   struts2
          
  
   /*
  
 


Create HelloWorldAction

Create the HelloWorldAction and MessageStore classes under org. apache. struts. helloworld. action and org. apache. struts. helloworld. model under the SRC directory. The content is as follows:

HelloWorldAction

package org.apache.struts.helloworld.action; import org.apache.struts.helloworld.model.MessageStore;import com.opensymphony.xwork2.ActionSupport; publicclass HelloWorldAction extendsActionSupport {     privatestaticfinallong serialVersionUID =1L;     private MessageStore messageStore;         public String execute()throws Exception {        messageStore =new MessageStore();        return SUCCESS;    }     public MessageStore getMessageStore(){        return messageStore;    }     publicvoid setMessageStore(MessageStore messageStore){        this.messageStore = messageStore;    } }


MessageStore

package org.apache.struts.helloworld.model; publicclass MessageStore {         private String message;         public MessageStore() {                 setMessage("Hello Struts User");    }     public String getMessage() {         returnmessage;    }     publicvoid setMessage(String message) {         this.message = message;    } }


Create struts. xml

Create a struts. xml file in the SRC directory. The content is as follows:

  
      
       
                       
   
    /index.jsp
                                
   
    /HelloWorld.jsp              
   
  
 


Create HelloWorld. jsp

The content of HelloWorld. jsp is as follows:

<%@ pagelanguage="java" import="java.util.*"pageEncoding="UTF-8"%><%@ taglibprefix="s" uri="/struts-tags" %>       Hello World          
   


Deployment and running

Deploy the StrutsDemo project to Tomcat, open the IE browser, and access: http: // localhost: 8080/StrutsDemo/hello. action

So far, Struts has been set up successfully.

Demo

Http://download.csdn.net/detail/zfz1214/6639157

Related Article

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.