struts2学习笔记之二_在项目中引入struts2

在项目中引入struts2

1.创建web项目
2.引入struts2类库
  ${struts解压目录}/app/struts2-blank-2.1.8.1.war/web-inf/lib/*.jar
3.创建action.
  package cn.itcast.struts2.action/*** HelloWorldAction*/

  public class HelloWorldAction {
    public String execute(){
    System.out.println("hello world");
    return null ;
    }
  }
4.创建struts配置文件.src/struts.xml
  dtd:struts-core.jar/struts-2.1.7.dtd/30行
  <?xml version="1.0"?>
  <!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
  "http://struts.apache.org/dtds/struts-2.1.7.dtd">
  <struts>
    <package name="HelloWorldPkg" namespace="/helloworld">
    <action name="HelloWorldAction"             

        class="cn.itcast.struts2.action.HelloWorldAction" />
    </package>
  </struts>
5.配置struts2的过滤器web-inf/web.xml文件中
类:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<?xml version="1.0" encoding="UTF-8"?>
  <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <filter>
    <filter-name>action</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>action</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

posted @ 2013-08-05 13:58  Avrilliu  阅读(352)  评论(0编辑  收藏  举报