Apache Struts is a free, open-source, MVC framework for creating elegant, modern Java web applications.
It favors convention over configuration, is extensible using a plugin architecture, and ships with plugins to support REST, AJAX and JSON.
1.下载 http://struts.apache.org/
2. "New" ===> "Dynamic Web Project" ===> 在创建项目时加上"web.xml"
3.解压"struts-2.5.5-min-lib.zip"将全部的jar包放到项目"WebContent"==>"WEB-INF"===>"lib"下
4.配置过滤器:参考范例,在项目的"web.xml"中加上以下内容
<!-- Filters -->
<!-- START SNIPPET: filter -->
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- END SNIPPET: filter -->
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5.配置struts.xml,可以从参考范例中找到"WEB-INF\classes\struts.xml"放到项目的"src"下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
</struts>
6.写一个"index.jsp"文件
部署====测试
官方实例:
参考官方文档:file:///C:/Users/lzhpc/Desktop/Struts2.5.5/struts-2.5.5-all/struts-2.5.5/docs/docs/home.html
参考案例:file:///C:/Users/lzhpc/Desktop/Struts2.5.5/struts-2.5.5-all/struts-2.5.5/docs/docs/hello-world-using-struts-2.html
Suppose you want to create a simple "Hello World" example that displays a welcome message. After setting up an empty basic Struts 2 web application (see How To Create A Struts 2 Web Application), to create a "Hello World" example, you need to do four things:
1>:Create a class to store the welcome message (the model)
创建一个类来存储欢迎消息(模型)
2>:Create a server page to present the message (the view)
创建一个服务器页面的消息(视图)
3>:Create an Action class to control the interaction between the user, the model, and the view (the controller)
创建一个Action类控制用户之间的交互,模型和视图(控制器)
4>:Create a mapping (struts.xml) to couple the Action class and view
It favors convention over configuration, is extensible using a plugin architecture, and ships with plugins to support REST, AJAX and JSON.
1.下载 http://struts.apache.org/
2. "New" ===> "Dynamic Web Project" ===> 在创建项目时加上"web.xml"
3.解压"struts-2.5.5-min-lib.zip"将全部的jar包放到项目"WebContent"==>"WEB-INF"===>"lib"下
4.配置过滤器:参考范例,在项目的"web.xml"中加上以下内容
<!-- Filters -->
<!-- START SNIPPET: filter -->
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- END SNIPPET: filter -->
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5.配置struts.xml,可以从参考范例中找到"WEB-INF\classes\struts.xml"放到项目的"src"下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
</struts>
6.写一个"index.jsp"文件
部署====测试
官方实例:
参考官方文档:file:///C:/Users/lzhpc/Desktop/Struts2.5.5/struts-2.5.5-all/struts-2.5.5/docs/docs/home.html
参考案例:file:///C:/Users/lzhpc/Desktop/Struts2.5.5/struts-2.5.5-all/struts-2.5.5/docs/docs/hello-world-using-struts-2.html
Suppose you want to create a simple "Hello World" example that displays a welcome message. After setting up an empty basic Struts 2 web application (see How To Create A Struts 2 Web Application), to create a "Hello World" example, you need to do four things:
1>:Create a class to store the welcome message (the model)
创建一个类来存储欢迎消息(模型)
2>:Create a server page to present the message (the view)
创建一个服务器页面的消息(视图)
3>:Create an Action class to control the interaction between the user, the model, and the view (the controller)
创建一个Action类控制用户之间的交互,模型和视图(控制器)
4>:Create a mapping (struts.xml) to couple the Action class and view
创建一个映射(struts.xml)夫妇Action类和视图