JavaWeb-Struts2-安装配置测试

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

   创建一个映射(struts.xml)夫妇Action类和视图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值