struts2---学习笔记1

相信学过一个框架的人在学习另一个框架时会非常的快,因为框架的学习无非是文件的配置、新类的熟悉。strurs2亦是如此。我这里不会把STRUTS2所有的开发过程给列出来,因为论坛上已经有很多大牛已经在做了。只是列举些思路及自己在学习过程中碰到的问题。本案适用的是2.1.8版本,可能跟其他版本存在些差异。

   1) web.xml配置过滤器 ,网络上很多教材在配置时用的是
        org.apache.struts2.dispatcher.FilterDispatcher
      因为是初学,并不是很了解这个过滤器是不是类似与struts1中的ActionServlet.不过自己在看struts2自带的blank包时,发现使用的是
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
     showcase实例则使用了三个过滤器
           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
           org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter
           com.opensymphony.module.sitemesh.filter.PageFilter
      其中具体的不同,还需要以后看源代码。

   2) struts.xml文件配置
        下面是的我的一个简单配置,因为继承的struts-default,所以简单修改了些属性
        <struts>

        <constant name="struts.enable.DynamicMethodInvocation"
                value="false" />
        <!-- 开发模式下 -->
        <constant name="struts.devMode" value="true" />
       
        <!--命名空间真的非常重要,简单说是为逻辑业务分区 -->
        <package name="struts2" namespace="/mystruts"
                extends="struts-default">
                <action name="sum" class="Action.FirstAction">
                        <result name="positive">/positive.jsp</result>
                        <result name="negative">/negative.jsp</result>
                </action>

                <action name="mulInput" class="Action.MulSubmitAction" method="save">
                        <result name="save">/mystruts/result.jsp</result>
                        <result name="print">/mystruts/result.jsp</result>
                </action>

        </package>
     </struts>

你可能感兴趣的:(apache,jsp,框架,xml,struts)