本篇文章给大家谈谈在JSFbean中获取请求URL?,以及jsp获取javabean的知识点,同时本文还将给你拓展16、在bean中获取Resource、c#–提供了无效的请求URI.请求URI必须是
本篇文章给大家谈谈在JSF bean中获取请求URL?,以及jsp获取javabean的知识点,同时本文还将给你拓展16、在bean中获取Resource、c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置BaseAddress、ios – UIWebView获取请求URL路径(html字符串)、JS获取请求URL带的参数等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- 在JSF bean中获取请求URL?(jsp获取javabean)
- 16、在bean中获取Resource
- c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置BaseAddress
- ios – UIWebView获取请求URL路径(html字符串)
- JS获取请求URL带的参数
在JSF bean中获取请求URL?(jsp获取javabean)
如何在支持JSF页面的bean中获得请求URL?我一直在浏览FacesContext文档,发现的最佳方法似乎很长:
public String getRequestURL()
{
Object request = FacesContext.getCurrentInstance().getExternalContext().getRequest();
if(request instanceof HttpServletRequest)
{
return ((HttpServletRequest) request).getRequestURL().toString();
}else
{
return "";
}
}
编辑:功能要求
这里的要求是我们需要第三方javascript实用程序的完整URL。该实用程序的使用或体系结构不适用于JSF,但除此调用外的所有内容都适用。我发现的方法可以用,但是深入研究FacesContext感觉不对。另外,我希望可以使用JSF表达式语言调用此方法,因为它将以与“视图”相关的方式使用。
16、在bean中获取Resource
本章我们讲如何在Bean中获取Resource,就是在Spring中如何向我们的Bean注入Resource。下面我们来实现这个功能。
编写Bean
这里我们实现一个工具类,用于读取Properties文件并提供一个方法用于根据key获取对应的值。
package com.codestd.springstudy.resource;
import java.util.Properties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
public class PropertiesUtils implements InitializingBean{
private Properties properties;
private Resource resource;
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
public void afterPropertiesSet() throws Exception {
properties = new Properties();
properties.load(this.resource.getInputStream());
}
public String get(String key){
return (String) this.properties.get(key);
}
}
Properties文件
spel/setup.properties
system.name=spel
配置Bean
<bean id="propertiesUtils" class="com.codestd.springstudy.resource.PropertiesUtils">
<property name="resource" value="classpath:spel/setup.properties"/>
</bean>
测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:resource/applicationContext.xml"})
public class PropertiesUtilsTest {
@Autowired
private PropertiesUtils propertiesUtils;
@Test
public void testGet() {
String value = this.propertiesUtils.get("system.name");
assertEquals("spel", value);
}
}
c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置BaseAddress
HttpClient http = new HttpClient(); var response = await http.GetByteArrayAsync("www.nsfund.ir/news?p_p_id=56_INSTANCE_tVzMoLp4zfGh&_56_INSTANCE_tVzMoLp4zfGh_mode=news&_56_INSTANCE_tVzMoLp4zfGh_newsId=3135919&p_p_state=maximized"); String source = Encoding.GetEncoding("utf-8").GetString(response,response.Length - 1); source = WebUtility.HtmlDecode(source); HtmlDocument resultat = new HtmlDocument(); resultat.LoadHtml(source);
但我得到这个错误:
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
解决方法
var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_....
ios – UIWebView获取请求URL路径(html字符串)
webView.loadHTMLString(finalHtml,baseURL:baseUrl)
当我在UIWebViewDelegate shouldStartLoadWithRequest中println(webView.request?.URL.path)时,我得到了点击路径为“/”的路径.
如果我用这个:
webView.loadHTMLString(finalHtml,baseURL:nil)
当我打印出来时,我得到“nil”(webView.request?.URL.path)
当然,我已将baseURL设置为原始网站,但根据我的理解,如果链接具有完整地址,则baseURL无关紧要.
有任何关于如何获得被点击的链接的标签中指示的实际路径的建议吗?提前谢谢你= D.
编辑当我长按链接时,会弹出一个显示正确链接的弹出窗口.我已经尝试了所有的东西,包括absoluteString,但我仍然不会得到路径.
解决方法
func webView(webView: UIWebView,shouldStartLoadWithRequest request: NSURLRequest,navigationType: UIWebViewNavigationType) -> Bool { if navigationType == .LinkClicked { println(request.URL.path) } return true }
如果要查看所有请求的路径(包括向后导航,转发等),请忽略if navigationType == .LinkClicked条件.
JS获取请求URL带的参数
//获取URL参数方法
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
我们今天的关于在JSF bean中获取请求URL?和jsp获取javabean的分享就到这里,谢谢您的阅读,如果想了解更多关于16、在bean中获取Resource、c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置BaseAddress、ios – UIWebView获取请求URL路径(html字符串)、JS获取请求URL带的参数的相关信息,可以在本站进行搜索。
本文标签: