You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

这个教程旨在教大家如何如何安装框架和创建一个简单的程序

(warning)  

Struts 2框架用起来很简单,这个教程假设你已经掌握如下J2EE技术:

  • Java
  • Filters, JSP, and Tag Libraries
  • JavaBeans
  • HTML and HTTP
  • Web Containers (such as Tomcat)
  • XML

Java需求

Struts 2 需要Servlet API 2.4或更高,JSP 2.0或更高和Java 5或更高

我们的第一个程序

为了开始使用Struts 2 我们将用ant建立一个web 应用程序,然后我们将用Maven建立同样的一个程序。

你可以从Google Code - http://code.google.com/p/struts2-examples/downloads/list下载所有的例子。

在下面选择一个你熟悉的技术(Ant或Maven)

Ant

你可以下载这个完整的例子,Basic_Struts_Ant下载地址上面已经说了。下载完了后解压缩,得到 Basic_Struts2_Ant这个目录,里面有Readme.txt它介绍了如何建立和运行这个程序。

为了建立这个程序你需要下载Struts 2并将其jar包加入到你的Classpath。下载入口Struts 2

Step 1 - 创建一个基本的Web程序

在你的java IDE 里面创建一个Web application project命名为Basic_Struts2_Ant,下面是截图


Step 2 - 添加一个index.jsp
添加一个简单的index.jsp页面,他的title是Basic Struts 2 Application - Welcome,他的内容是Welcome to Struts 2!

然后在eclipse中运行该项目
Step 3 - 添加Struts 2的jar文件到Class Path

我们添加Struts 2最小需求的jar包。我们将把这些jar包拷贝到WEB-INF\lib这个文件夹中。

找到并拷贝这些文件

  1. asm-x.x.jar
  2. asm-commons-x.x.jar
  3. asm-tree-x.x.jar
  4. commons-fileupload-X.X.X.jar
  5. commons-io-X.X.X.jar
  6. commons-lang3-X.X.X.jar
  7. commons-fileupload-X.X.X.jar
  8. freemarker-X.X.X.jar
  9. javassist-X.X.X.jar
  10. ognl-X.X.X.jar
  11. struts2-core-X.X.X.X.jar
  12. xwork-core-X.X.X.jar

You can see from the above that the Struts 2 core jar depends on several other artifacts. As we add additional Struts 2 features in future tutorials, we'll need to add additional Struts 2 jar files and other transitive dependencies.

Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application

  • No labels