http://localhost:8080/app/subapp/action/method/1

ホスト名以降、「メインアプリ/サブアプリ/アクション/メソッド/パラメータ」とします。

SAStrutsでこのURLにアクセスした場合の、<s:link>と<html:link>の挙動を比較してみます。

s:link

以下、公式リファレンスの引用です。

SAStrutsには、Strutsのhtml:linkを継承したs:linkが用意されています。 href属性を設定するときに、コンテキストルートを自動的に補完させる場合に使います。パスを/ではじめた場合は、コンテキストルートからみたパスになります。パスが/ではじまっていない場合は、JSPからみたパスになります。

Super Agile Struts - Feature Reference

JSP
<s:linkhref="">A</s:link>
<s:linkhref="link">B</s:link>
<s:linkhref="./">C</s:link>
<s:linkhref="./link">D</s:link>
<s:linkhref="../">E</s:link>
<s:linkhref="http://www.cnblogs.com/">F</s:link>
<s:linkhref="/">G</s:link>
<s:linkhref="/link">H</s:link>
出力html

想定される遷移先をコメントで示しています。

<ahref="/app/subapp/action/">A</a>         <!-- 同じアクションのindexメソッド -->
<ahref="/app/subapp/action/link">B</a>     <!-- 同じアクションのlinkメソッド -->
<ahref="/app/subapp/action/./">C</a>       <!-- 同じアクションのindexメソッド -->
<ahref="/app/subapp/action/./link">D</a>   <!-- 同じアクションのlinkメソッド -->
<ahref="/app/subapp/action/../">E</a>      <!-- サブアプリのIndexアクション -->
<ahref="/app/subapp/action/http://www.cnblogs.com/">F</a>   <!-- メインアプリのIndexアクション -->
<ahref="/app/">G</a>                       <!-- メインアプリのIndexアクション -->
<ahref="/app/link">H</a>                   <!-- メインアプリのLinkアクション -->
遷移先URL
A http://localhost:8080/app/subapp/action/
B http://localhost:8080/app/subapp/action/link
C http://localhost:8080/app/subapp/action/
D http://localhost:8080/app/subapp/action/link
E http://localhost:8080/app/subapp/
F http://localhost:8080/app/
G http://localhost:8080/app/
H http://localhost:8080/app/link

html:link

JSP
<html:linkhref="">A</html:link>
<html:linkhref="link">B</html:link>
<html:linkhref="./">C</html:link>
<html:linkhref="./link">D</html:link>
<html:linkhref="../">E</html:link>
<html:linkhref="http://www.cnblogs.com/">F</html:link>
<html:linkhref="/">G</html:link>
<html:linkhref="/link">H</html:link>
出力html
<ahref="">A</a>        <!-- 同じアクションの同じメソッド、同じパラメータ -->
<ahref="link">B</a>    <!-- 同じアクションの同じメソッド、linkパラメータ -->
<ahref="./">C</a>      <!-- 同じアクションの同じメソッド、パラメータなし -->
<ahref="./link">D</a>  <!-- 同じアクションの同じメソッド、linkパラメータ -->
<ahref="../">E</a>     <!-- 同じアクションのindexメソッド -->
<ahref="http://www.cnblogs.com/">F</a>  <!-- サブアプリのIndexアクション -->
<ahref="/">G</a>       <!-- ドキュメントルート -->
<ahref="/link">H</a>   <!-- 別のWebアプリ -->
遷移先URL
A http://localhost:8080/app/subapp/action/method/1
B http://localhost:8080/app/subapp/action/method/link
C http://localhost:8080/app/subapp/action/method/
D http://localhost:8080/app/subapp/action/method/link
E http://localhost:8080/app/subapp/action/
F http://localhost:8080/app/subapp/
G http://localhost:8080/
H http://localhost:8080/link

まとめ

基本的には、<s:link>を使うのが良いと思います。<html:link>だと、以下の場合に遷移先URLが異なってしまいます。

※ html:link 「/」で終わるURLの場合
http://localhost:8080/app/subapp/action/method/1/
A http://localhost:8080/app/subapp/action/method/1/
B http://localhost:8080/app/subapp/action/method/1/link
C http://localhost:8080/app/subapp/action/method/1/
D http://localhost:8080/app/subapp/action/method/1/link
E http://localhost:8080/app/subapp/action/method/
F http://localhost:8080/app/subapp/action/

<s:link>であれば、「/」で終わっていても同じURLになります。自動補完により、必ず絶対パスで出力されるためです。

转载于:https://www.cnblogs.com/aggavara/archive/2012/09/29/2708713.html

SAStruts リンク記述におけるs:linkとhtml:linkの比較相关推荐

  1. 单点故障解决方案介绍smart link/monitor link /stp

    文章目录 以太网单点故障 单点故障解决方案之Smart Link 单设备"链路备份"方案 Smart Link之链路正常 Smart Link之链路故障 Smart Link的基础 ...

  2. Smart Link Monitor Link

    Smart Link & Monitor Link 工作原理 当下游设备连接到上游设备时,使用单上行方式容易出现单点故障,造成业务中断.因此通常采用双上行方式,即将一台下游设备同时连接到两台上 ...

  3. 10.文件系统的简单操作(hard link soft link)

    df : 列出文件系统的整体磁盘使用量-a : 列出所有文件系统 -k : kb -m : mb -h : g -i : 以 inode 数量显示 du : 评估文件系统的磁盘使用量(常用于评估目录所 ...

  4. java link 使用_Java数据结构之简单的连接点(link)实现方法示例

    本文实例讲述了Java数据结构之简单的连接点(link)实现方法.分享给大家供大家参考,具体如下: 一.概述: 链接点由:数据和指向下个数据的指针构成 如图: 二.简单实现: package com. ...

  5. 网页编程html link,Web--CSS控制页面(link与import方式区别)详解

    先了解: [1]       "Table"和"DIV"这两个网页元素诞生的目的不同,首先Table诞生的目的是为了存储数据,而DIV诞生的目的就是为了架设页面 ...

  6. Linux中link,unlink,close,fclose详解

    unlink系统调用] 功能描述: 从文件系统中删除一个名称.如果名称是文件的最后一个连接,并且没有其它进程将文件打开,名称对应的文件会实际被删除. 用法: #include <unistd.h ...

  7. processing link链接

    void draw() { rect(20, 20, 60, 60); } void mousePressed() { link("http://processingjs.org" ...

  8. ueditor php 网络链接错误,ueditor使用editor.execCommand( 'link', {})插入链接无效的问题...

    介绍 因为项目需要,所以要在百度富文本编辑器ueditor上二次开发,有一个就是在富文本中插入链接的功能: 官方文档如下: execCommand(String cmd, Object options ...

  9. html语言head里面的link示例,Html之head部分详解(示例代码)

    随便打开一个网页,右击查看网页源代码,总能看到 -封闭标签,在里面通常会包含5类标签:title.link.script.meta.style.这5类标签看着都挺熟悉的哈,那么在web前端技术中具体要 ...

最新文章

  1. 数据结构之链表反向打印
  2. 安装Axis2的eclipse插件后,未出现界面
  3. 电脑总是跳出错误报告
  4. r语言向量代码如何创建函数c,R中向量基本操作:创建、运算、访问
  5. java实现Hbase中的查询(一)Filter方式
  6. Cannot run program /opt/CI/android-sdk-linux/build-tools/26.0.0/aapt: error=13, Permission denied
  7. 【招聘(深圳)】迈瑞招.NET 开发Leader和PM
  8. nginx配置静态资源允许跨域访问
  9. 重磅!清华商汤开源CVPR2018超高精度人脸对齐算法LAB
  10. 渗透测试入门24之渗透测试参考书、课程、工具、认证
  11. oracle 约束 年份,如何在Oracle中确定给定年份是否为Le年?
  12. 【论文写作】毕业论文写作套路之正文(2)
  13. android语音识别服务,使用语音服务 API 的语音识别 - Xamarin | Microsoft Docs
  14. c语言编程统计磁盘文件,C语言编程题经典40题(附解答).ppt
  15. linux redis 工具,linux下redis安装 + 工具 putty
  16. 马克思主义原理复习资料笔记
  17. 四川取消英语计算机考试,四川远程教育2019年英语考试取消了吗
  18. 非Build Rebuild--Compilation of Maven projects is supported only if external build is started from an
  19. 第一篇:微信公众平台开发实战Java版之了解微信公众平台基础知识以及资料准备
  20. 基于MATLAB APP Designer 和 Python 的音视频剪辑

热门文章

  1. SPOJ- QTREE+HDU 3966(树链剖分裸题
  2. HTML5主要新增标签
  3. 最新卡通渲染效果图(附带一张次世代帅哥)
  4. Valve开发校准软件,LCD屏也能与高端VR头显适配了
  5. 前端学习 -- HtmlCss -- 框架集
  6. 双11不过瘾?双十二低至半价继续抢,更有免费学的机会等你抢!
  7. 解决Maven报Plugin execution not covered by lifecycle configuration
  8. RAC+单实例DATAGUARD 配置
  9. Android 应用程序消息处理机制(Looper、Handler)分析
  10. android Glide简单使用