首页 > 其他 > 详细

struts2的配置

时间:2017-01-08 19:08:35      阅读:307      评论:0      收藏:0      [点我收藏+]

1、目录结构

技术分享

要导入包进lib(在idea中lib要有一定的设置):http://download.csdn.net/detail/cainiaobegin/9732077

 

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";
    }
}

 

struts2的配置

原文:http://www.cnblogs.com/xiaolonghome/p/6262324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!