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