接触Struts2 第一个例子

来源:互联网 发布:淘宝买家具靠谱吗 编辑:程序博客网 时间:2024/05/31 13:16



struts2 一个例子

1.导入jar包

2.编写一个hellowordaction类

public class helloworldaction

{

public String execute()

{

return "index";

}

}

3.添加一个struts.xml

<struts><package name="helloworld" namespace="/" extends="struts-default"><action name="helloworldaction" class="cn.hpy.structs.action.HelloWorldAction"><result name="index">index.jsp</result></action></package></struts>

4.编写web.xml

   <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>


总结

1.在web.xml中,只需要一个过滤器,不用繁琐的配置;

2.action就是一个简单javabean,与servlet容器没有以来;

3.有一个配置文件struts.xml,配置了url 和决定跳转的页面;



0 0
原创粉丝点击