Struts2.0从使用到精通

2019-03-21  本文已影响0人  Mr_苦行僧

Struts2.0从使用到精通

导语

 strut2.0 其实就是为了我们封装了servlet,简化了jsp的跳转的复杂操作,并且提供了易于
 编写的标签,可以快速开发view层的代码,过去,我们用jsp和servlet搭配,实现展现时,大体的过程是:

与不用框架比较

  1. jsp触发action
  2. servlet接受action,交给后台的class处理
  3. 后台的class跳转到其他的jsp,实现数据展现
 strut2.0
  1. jsp发出action
  2. structs2.0拦截请求,调用后台action
  3. action返回结果,由不同的jsp展现数据
集成的步骤:
image
<?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"
       xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       id="WebApp_ID" version="2.5">
     <filter>
              <filter-name>struts</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>HelloWorld.jsp</welcome-file>
             </welcome-file-list>
</web-app>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="com" extends="struts-default">
        <action name="HelloWorld" class="com.HelloWorld">
            <result>/HelloWorld.jsp</result>
        </action>
        <!—这里是我添加的一个action -->
    </package>
</struts>

到此struts2.0框架配置完成。下一节讲struts2.0框架的工作原理。

上一篇 下一篇

猜你喜欢

热点阅读