zoukankan      html  css  js  c++  java
  • 11.使用ForwardAction实现页面屏蔽。

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html

    我们在jsp页面之间写链接总会是.../xxx.jsp,而如果我们想屏蔽掉具体的jsp,只需要所jsp页面配置成一个ForwardAction即可实现。示例如下:在根目录下有一个index.jsp主页,我们strtus.xml中作如下配置:

    <package name="def" extends="struts-default">             

                  <action name="forward">

                         <result >/index.jsp</result>

                  </action>

    </package>

    说明:如果没有未action指定class,默认就是ActionSupport类,如果没有为action指定method属性,则默认执行execute方法,如果没有指定result的name属性,默认值为success。知道了这些再结合ActionSupport的源码就不难理解实现转发的原理了。
    随后再在前面第7点扩展中用到的op.jsp中增加如下代码:
    <a href="<%=request.getContextPath()%>/forward.action">forward</a>

    最后再测试访问op.jsp,在op.jsp中页面中直接点链接便可以跳到index.jsp,观察地址栏发现此时跳到index页面是进行的服务器跳转,如果我们在上面的配置中的result增加type属性变成<result type="redirect">/index.jsp</result>,实现的跳转就是客户端跳转。 补充:像这种forward形式的action实质是执行的ActionSupport 这个Action。因此配置它的result可以参看此类的api文档,比如它常用的result name有:success、login、input等。

  • 相关阅读:
    Selenium(一):元素定位
    白盒测试系列(五)条件组合覆盖
    LDAP(轻型目录访问协议)
    Spring Intorduce、History and Design Philosophy
    CORS
    mysql创建用户并授权某个数据库
    Introduce Servlet 、Filter
    web.xml的简单解释以及Hello1中web.xml的简单分析
    ANNOTATION and analyse hello1.java
    Analysis of container and Injection in Java, their history and future.
  • 原文地址:https://www.cnblogs.com/sharpest/p/5580577.html
Copyright © 2011-2022 走看看