Struts2初探

  我记得美妙的瞬间;在我的面前出现了你,有如昙花一现的幻影

  今天写一篇Struts2框架的,在很久很久以前,Struts2可谓是称霸江湖,纵然现在有后起之秀,但Struts2依然可以成为老牌的主流框架,充当servlet,而且现在很多的招聘需求依然要求你会用Struts2,并且有的面试官会问你它和SpringMvc的区别,今天先把代码展示出来,对应的理论知识在初探—续编里面在详细表述。

目录结构:

 

HelloWorld.java

 1 package Action;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class HelloWorld extends ActionSupport{
 6     @Override
 7     public String execute() throws Exception {
 8         // TODO Auto-generated method stub
 9         System.out.println("执行ACtion");
10         return SUCCESS;
11     }
12 }

Struts.xml 配置文件

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 <struts>
 6     <package name="default" extends="struts-default">
 7         <action name="HelloWorld" class="Action.HelloWorld">
 8             <result name="success">/index.jsp</result>
 9         </action> 
10     </package>
11 </struts>

Web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" 
 3     xmlns="http://java.sun.com/xml/ns/javaee" 
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 6     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 7   <display-name></display-name>    
 8   
 9   <filter>
10       <filter-name>struts2</filter-name>
11     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
12   </filter>
13   
14   <filter-mapping>
15   <filter-name>struts2</filter-name>
16   <url-pattern>/*</url-pattern>
17   </filter-mapping>
18   <welcome-file-list>
19     <welcome-file>index.jsp</welcome-file>
20   </welcome-file-list>
21 </web-app>

 

jsp 展示页

 后续还有Struts2的很多文章,敬请期待!

posted @ 2017-11-21 00:04  文刀山豆几  阅读(361)  评论(3编辑  收藏  举报