4 回答
没有区别。这取决于prefix
如果你使用这个
<%@ taglib prefix="s" uri="/struts-tags" %>
然后使用
<s:select>
如果你使用这个
<%@ taglib prefix="html" uri="/struts-tags" %>
<html:select>
然后使用
Both tags have the same name but different namespaces defined by the tag prefix.
If you want to use some other tag library that has tags with names you have already in use then better define those tag libraries under different namespaces, so tag names doesn't clash to achieve the different behavior.
To make sure the tag names didn't clash better to use other tag libraries prefixed with different namespaces.
<html:select>
和<html:something
标签是Struts 1标签库的一部分,特别是tags-html库:
<%@taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<html:select ...>
, while<s:select>
和<s:something
tags 是Struts 2标签库的一部分,特别是struts-tags库:
<%@taglib prefix="s" uri="/struts-tags" %>
<s:select ...>
编辑
正如@UmeshAwasthi 让我注意到的那样,这可能不是一个约定,而不是代码语法;
这意味着,如果某个不喜欢标准的疯子想要反转标签库的前缀HE CAN,就像他可以写的一样Integer myDouble = new Integer();
……只是语义被破坏了,语法是好的。
但是,由于我猜你的问题产生的疑问(我几年前也有)是由于这两种语法(<html:
和<s:
)在网络上多次出现,相信我,它们总是引用正确的库(在至少在在线文章中,也许并不总是在这里或在coderanch等问题中出现)。
总而言之,公约(不是规则,只是规则)是:
html = Struts 1
s = Struts 2
c = JSTL
Well it dependents upon in what respect you are talking about and both above answer are correct in there own way.
There can be two aspects here
- You are mixing Struts old version with Struts2.
- This is just a preferred way to use prefix by the developer.
Generally all who have worked with Struts old version are well known about using html
as tag prefix and is very well explained by Andrea Ligios.
in general when we use Struts2 tag we use s as prefix but this is only a convention and you can use any convention (prefix) like <s:select>, <html:select>, <myprefix:select>
.
All you need to tell framework what prefix, you wan to use with the help of following line in you template file
<%@taglib prefix="prefix of you choice" uri="/struts-tags" %>
Though i am sure that you might have seen code at tow places with one represents old Strut and other represents Struts2 version.