struts2的配置

1、目录结构

要导入包进lib:http://download.csdn.net/detail/cainiaobegin/9732748

 

2、index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>
<a href="test!test1.action">test1</a>
  <br>
  <a href="test!test2.action">test2</a>
  </body>
</html>

3、struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
   <package name="default" extends="struts-default"> 
     
         <action name="test_*" class="action.Test" method="{1}">
               <result name="test1"> test1.jsp</result>
               <result name="test2"> test2.jsp</result>
         </action>
    </package>
</struts>

4、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

5、Test.java

package action;
public class Test {
    public String test1(){
        return "test1";
    }
    public String test2(){
        return "test2";
    }
}

 

posted on 2017-01-08 17:27  丨丿丶  阅读(120)  评论(0编辑  收藏  举报