.一、struts2搭建环境及运行机制

action

result

常用配置文件      

ongl & valueStack
tags标签
project----类型转换、上传与下载、interceptor、重复提交
MVC思想深入剖析
源码解读
其他话题----校验框架、异常处理
 
一、安装与设置
 
1. 新建项目:
    a)   选择[myeclipse] [java enterprise projects] [web project]
    b)   项目名称:struts2_0100_introduction
    c)   选择java ee 5.0
2. 设定server
    a)   [window] [preferences] [myeclipse] [servers] [tomcat] [tomcat 6.x]
    b)   选择tomcat home directory
    c)   选择enable
    d)   finish
3. 设定jdk环境
    a)  [window] [preferences] [java] [installed jres]
    b)  如果没有对应的JDK(不是JRE),选择add
    c)  选择standard VM -> next
    d)  选择JDK对应的Directory
    e)  将刚刚设定的JDK设为默认
 
二、 准备工作及实例
 
解压struts-2.1.6-all.zip  
    apps目录:struts2自带的例子程序。如:struts2-blank.war( 最基础的示例程序 )

    docs目录:官方文档

    lib 目录:存放所有类库jar文件

    Src 目录:源码

 进入 struts-2.1.6\apps\struts2-blank-2.1.6\WEB-INF 下:

    a)  复制struts.xml文件。classes下面的struts.xml,拷到web工程的src下面,因为工程编译完它默认就把src下的文件放到class文件下面。

      <struts>

        <!-- <constant> 常量的配置。 -->

        <!-- name="struts.devMode" value="true" 开发模式改为true之后,修改配置文件可以马上生效,不用重启服务器。 -->

        <constant name="struts.devMode" value="true" />

扫描二维码关注公众号,回复: 671314 查看本文章

        <package name="default" namespace="/" extends="struts-default">

            <action name="hello">

                <result>/hello.jsp</result>

            </action>

        </package>

     </struts>

http://localhost:8080/strust2_0100_Introduction/[U1] 

http://localhost:8080/strust2_0100_Introduction/hello 或者

http://localhost:8080/strust2_0100_Introduction/hello.action[U2] 


 [U1]这里的“/”对应namespace的“/,因为action name属性为hello,所以敲

 [U2]默认的aciton是可以省略的

    b)  复制类库。lib下面的jar文件,需要除junit和spring-test之外的所有文件,其中commons-io的jar包会在文件上传和下载时需要,其他为必须。(jar放入lib后看不见jar文件,是因为MyEclipse默认视图是package Explorer,如果要看硬盘上对应的视图,应该打开[windows] [Show View] [other] [navigatior]

            struts2-core-2.1.6.jar 开发的核心类库
            freemarker-2.3.13.jar
struts2UI标签的模板使用freemarker编写
            commons-logging-1.0.4.jar 日志包
            ognl-2.6.11.jar
对象图导航语言,通过它来读写对象属性
            xwork-2.1.2.jar xwork类库,struts2在其上进行构建
            commons-fileupload-1.2.1.jar
文件上传组件,2.1.6版本后必须加入此jar

   c)  配置web.xml。复制web.xml的filter 和filter-mapping,到web工程的web.xml中。

      <filter>

猜你喜欢

转载自tochangjin.iteye.com/blog/1613348