java的三大框架(二)---Struts2

Strtu2框架

1.控制器:ActionServlet充当控制层

2.模型层:由ActionForm及业务JavaBean实现

3.视图:用户的看到并与之交互的界面   由struts标签库和jsp页面实现的视图层

 

第一个简单的Struts2的程序


(1)创建工程,将Struts2的支持类库的web_inf目录下的lib文件拷贝到工程下的lib目录下,并添加到工程中

(2)在web.xml中生命Struts2提供的过滤器

 

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>MyStrut2</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
   <filter-name>MyStrut2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>MyStrut2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
(3)在工程src的目录下,创建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" namespace="/" extends="struts-default">
<action name="first">
<result>/first.jsp</result>
</action>
   </package>
</struts>
(4)创建index.jsp和first.jsp
 <body>
<a href="first.action">请求Strut2</a>
</body>
 
 <body>
第一个Struts2程序<br>
</body>
 
 
 
Action:Struts的重要对象,在Struts2API中,Action对象是一个接口
 

posted on 2017-05-21 22:36  &大飞  阅读(159)  评论(0编辑  收藏  举报

导航