如何使用URLshell 字符串参数传递来传递参数到JSF程序中

JavaScript indexOf() 方法
JavaScript indexOf() 方法
定义和用法
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
stringObject.indexOf(searchvalue,fromindex)
searchvalue
必需。规定需检索的字符串值。
可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略该参数,则将从字符串的首字符开始检索。
该方法将从头到尾地检索字符串 stringObject,看它是否含有子串 searchvalue。开始检索的位置在字符串的 fromindex 处或字符串的开头(没有指定 fromindex 时)。如果找到一个 searchvalue,则返回 searchvalue 的第一次出现的位置。stringObject 中的字符位置是从 0 开始的。
提示和注释
注释:indexOf() 方法对大小写敏感!
注释:如果要检索的字符串值没有出现,则该方法返回 -1。
在本例中,我们将在 &Hello world!& 字符串内进行不同的检索:
&script type=&text/javascript&&
var str=&Hello world!&
document.write(str.indexOf(&Hello&) + &&br /&&)
document.write(str.indexOf(&World&) + &&br /&&)
document.write(str.indexOf(&world&))
以上代码的输出:
如何使用 indexOf() 在字符串内进行检索。Stack Overflow - Where Developers Learn, Share, & Build Careers
Learn, Share, Build
Each month, over 50 million developers come to Stack Overflow to learn, share their knowledge, and build their careers.
Join the world’s largest developer community.
Display name
Email address
By registering, you agree to the
Stack Overflow Business Solutions: Looking to understand, engage, or hire developers?
Looking for more? Browse the , or . Help us answer .
Stack Overflow works best with JavaScript enabled在JavaScript中获取请求的URL参数[正则]
转载 & & 作者:
在ASP.NET后台代码中,对于这样的URL请求地址:http://www.abc.com?id=001,我们可以通过Request.QueryString[&id&]的方法很容易的获取到URL中请求的参数的值,但是要在前台js代码中获取请求的参数的值,应该怎么做呢?
第一种方法:,代码比较专业 推荐 代码如下:&script& function GetLocationParam(param){ var request = { QueryString : function(val) { var uri = window.location. var re = new RegExp("" +val+ "=([^&?]*)", "ig"); return ((uri.match(re))?(decodeURI(uri.match(re)[0].substr(val.length+1))):''); } } return request.QueryString(param); } var uid=GetLocationParam("uid"); &/script&第二种方法:当然我们可以在后台中获取参数的值,然后在前台js代码中获取变量的值,具体做法请参考我的这篇文章:JavaScript获取后台C#变量以及调用后台方法。 其实我们也可以直接在js中获取请求的参数的值,通过使用window.location.search可以获取到当前URL的?号开始的字符串,如前面的链接获取到的search为?id=001。再对获取的字符串进行处理,就可以获取到参数的值了。
代码如下: function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]);
在调用上面的方法的时候,只要传入参数的名称,就可以获取到你想要的参数的值了,如:getUrlParam("id")。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具How to include another XHTML in XHTML using JSF 2.0 Facelets? - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
What is the most correct way to include another XHTML page in an XHTML page? I have been trying different ways, none of them are working.
787k26829443059
1,77973051
&ui:include&
Most basic way is . The included content must be placed inside .
Kickoff example of the master page /page.xhtml:
&!DOCTYPE html&
&html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&
&title&Include demo&/title&
&h1&Master page&/h1&
&p&Master page blah blah lorem ipsum&/p&
&ui:include src="/WEB-INF/include.xhtml" /&
The include page /WEB-INF/include.xhtml (yes, this is the file in its entirety, any tags outside &ui:composition& are unnecessary as they are ignored by Facelets anyway):
&ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&
&h2&Include page&/h2&
&p&Include page blah blah lorem ipsum&/p&
&/ui:composition&
This needs to be opened by /page.xhtml. Do note that you don't need to repeat &html&, &h:head& and &h:body& inside the include file as that would otherwise result in .
You can use a dynamic EL expression in &ui:include src&. See also .
&ui:define&/&ui:insert&
A more advanced way of including is templating. This includes basically the other way round. The master template page should use
to declare places to insert defined template content. The template client page which is using the master template page should use
to define the template content which is to be inserted.
Master template page /WEB-INF/template.xhtml (as a design hint: the header, menu and footer can in turn even be &ui:include& files):
&!DOCTYPE html&
&html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&
&title&&ui:insert name="title"&Default title&/ui:insert&&/title&
&div id="header"&Header&/div&
&div id="menu"&Menu&/div&
&div id="content"&&ui:insert name="content"&Default content&/ui:insert&&/div&
&div id="footer"&Footer&/div&
Template client page /page.xhtml (note the template also here, this is the file in its entirety):
&ui:composition template="/WEB-INF/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&
&ui:define name="title"&
New page title here
&/ui:define&
&ui:define name="content"&
&h1&New content here&/h1&
&p&Blah blah&/p&
&/ui:define&
&/ui:composition&
This needs to be opened by /page.xhtml. If there is no &ui:define&, then the default content inside &ui:insert& will be displayed instead, if any.
&ui:param&
You can pass parameters to &ui:include& or &ui:composition template& by .
&ui:include ...&
&ui:param name="foo" value="#{bean.foo}" /&
&/ui:include&
&ui:composition template="..."&
&ui:param name="foo" value="#{bean.foo}" /&
&/ui:composition &
Inside the include/template file, it'll be available as #{foo}. In case you need to pass "many" parameters to &ui:include&, then you'd better consider registering the include file as a tagfile, so that you can ultimately use it like so &my:tagname foo="#{bean.foo}"&. See also
You can even pass whole beans, methods and parameters via &ui:param&. See also
Design hints
The files which aren't supposed to be publicly accessible by just entering/guessing its URL, need to be placed in /WEB-INF folder, like as the include file and the template file in above example. See also
There doesn't need to be any markup (HTML code) outside &ui:composition& and &ui:define&. You can put any, but they will be ignored by Facelets. Putting markup in there is only useful for web designers. See also
The HTML5 doctype is the recommended doctype these days, "in spite of" that it's a XHTML file. You should see XHTML as a language which allows you to produce HTML output using a XML based tool. See also
CSS/JS/image files can be included as dynamically relocatable/localized/versioned resources. See also
You can put Facelets files in a reusable JAR file. See also .
For real world examples of advanced Facelets templating, check the src/main/webapp folder of
787k26829443059
Included page:
&!-- opening and closing tags of included page --&
&ui:composition ...&
&/ui:composition&
Including page:
&!--the inclusion line in the including page with the content--&
&ui:include src="yourFile.xhtml"/&
You start your included xhtml file with ui:composition as shown above.
You include that file with ui:include in the including xhtml file as also shown above.
1,06431224
1,00731740
protected by
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10
on this site (the ).
Would you like to answer one of these
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
ends Mar 27
Stack Overflow works best with JavaScript enabled他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)}

我要回帖

更多关于 字符串参数传递 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信