• 学习Struts2经验总结


    一、struts 访问路径问题

    1) Struts2的思想:主要围着“action”转,只要找到“action”它就知道自己该干嘛了。

      首先配置struts.xml ,我们可以明白的看到,action name="index",而result 需要返回到一个界面“index.jsp”

    <struts>

    <package name="default" namespace="/" extends="struts-default">
    <action name="index">

    <result >

    /index.jsp
    </result>
    </action>
    </package>

    </struts>

    2 )修改“index.jsp” ,只输出一句话:Hello Struts2!

    <title>首页</title>
    </head>
    <body>
    Hello Struts2!
    </body>

    3)部署项目,重启tomcat7.0 在地址栏输入  http://localhost:8080/Struts1/index (或者http://localhost:8080/Struts1/index.action)——>回车,结果如下:

    4) 当我们改动了“action”的 “name”,其他地方不变,相应的在地址栏也改动它的名字,但是不会再有之前的结果,报错(找不到"action")。

    <struts>

    <package name="default" namespace="/" extends="struts-default"> 
    <action name="hello"> 
    <result > 
    /index.jsp
    </result> 
    </action> 
    </package>

    </struts>

    结果:

     

     

    5)解决办法:由上可知,这种情况需要重启服务,重新部署项目。现在有一个一劳永逸的方法:在struts.xml文件里加入常量 <constant name="struts.devMode" value="true" /> 使得一直处于开发模式(即Development Mode)(需要注意的是:要把value的默认值“false”改为“true”,才能是开发模式)。然后需要重启服务,再次运行,成功。

    为了验证该方法是否有效,可以再将“action” name改为之前的“index” ,但是不重启服务,直接运行,实践证明:此方法可行。

    6) 技巧总结i:1 写程序时可以运用的小技巧:地址栏需要输入对应的项目名称,但是太长了容易写错,没关系

                     此时直接单击项目——>右键——>copy Qualified Name,即可将项目名称准确无误的填入地址栏。

                  2.当想看struts jar包的源代码,直接单击目录: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter,只会看到这个界面

     不用急,可以如下操作:在struts2-core-2.2.1.jar文件上右键——>Properties——>Java Source Attachment——>External Folder(外部目录)——>OK。需要注意的是路径不能错。

      同样,要看它的doc文档,struts2-core-2.2.1.jar文件上右键——>Properties——>Javadoc Location——>Browse——>OK——>新建class——>粘贴web.xml中的一句话:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  f;——> 按下f1,即可看到右边的“help”目录下的doc文档。

    本文来自博客园,作者:💞Travelerᘗ,转载请注明原文链接:https://www.cnblogs.com/LindaBlog/p/5337780.html

  • 相关阅读:
    php.ini中Magic_Quotes_Gpc开关设置
    This is the Manual for Quagga 1.2.0. Quagga is a fork of GNU Zebra
    Are virtual interfaces supported on Quagga v0.98.3 (on Debian GNU/Linux 2.6.16)?
    [quagga-users 8071] Re: Virtual interfaces / aliases supported?
    quagga-0.99.20mr2.1
    Equal Cost Multipath Load Sharing
    (ECMP) Equal-cost multi-path routing
    Multipath suport not working in quagga 0.98.6
    Android-x86-7.1.1
    Android
  • 原文地址:https://www.cnblogs.com/LindaBlog/p/5337780.html
Copyright © 2020-2023  润新知