Struts2.1学习笔记_01

到struts官方上下载最新的struts非测试版本,解压后找到示例程序app目录下找struts2-blank,就是空的struts2示例。拷贝struts.xml到项目中src。再从lib目录拷贝struts2.1必须的包。

struts2.1所需要的包:

  • commons-fileupload-1.2.1.jar
  • commons-io-1.3.2.jar
  • freemarker-2.3.15.jar
  • ognl-2.7.3.jar
  • struts2-core-2.1.8.1.jar
  • xwork-core-2.1.6.jar
  • commons-logging-1.1.jar (自己加上)

最好把这些内容准备为MyEclipse的库,具体不多说。

 

修改项目中的web.xml文件,在其中加入struts2.1的过滤器。

代码如下:

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
       </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

 

修改struts.xml配置文件。从struts标签里的全部注释掉。写第一个helloworld。加入配置:

 

<package name="default" namespace="/" extends="struts-default">
        <action name="hello">
            <result>
                 /index.jsp
            </result>
        </action>
</package>

 

访问http://localhost:8080/项目/hello

 

看到inde.jsp页面

 

在struts.xml中的struts标签中加入常量,设置为开发模式。这样修改struts.xml后马上就会生效。

 

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

  

 

你可能感兴趣的:(xml,jsp,freemarker,MyEclipse,struts)