我一直在学习 React 和 Redux,并且注意到<Link>在使用 React-Router 时有两种以编程方式更改 URL 的方法(不使用 )。
一种方法是直接推送到browserHistory.
import React from 'react';
import { browserHistory } from 'react-router';
class Name extends React.Component {
gotoPage() {
browserHistory.push('/page');
}
render() {
return <div onClick={this.gotoPage.bind(this)}>Hello</div>
}
}
Run Code Online (Sandbox Code Playgroud)
另一种是推向this.context.router。
import React, { PropTypes } from 'react';
import { browserHistory } from 'react-router';
class Name extends React.Component {
static contextTypes = {
router: PropTypes.object
};
gotoPage() {
this.context.router.push('/page');
}
render() {
return <div onClick={this.gotoPage.bind(this)}>Hello</div>
}
}
Run Code Online (Sandbox Code Playgroud)
我应该使用其中一种而不是另一种吗?
我正在阅读Javascript原型属性如何与继承一起工作,然后开始查看Angular.js代码并提出了一些问题.
首先,我读到prototype属性指向一个具有"constructor"属性的对象,该属性指向用于创建对象的原始函数.例如:
// This is the constructor
function Shape() {
this.position = 1;
}
// The constructor points back to the original function we defined
Shape.protoype.constructor == Shape;
Run Code Online (Sandbox Code Playgroud)
原型还包含由我们或Javascript语言本身定义的任何其他方法或属性,并且这些方法或属性由对象的所有实例共享.如果你想让一个名为Square的对象继承自Shape,你需要设置Square的原型等于Shape的一个新实例,因为Square.prototype的内部[[prototype]]属性被设置为Shape.prototype属性的公共对象值. .
function Square() {}
Square.prototype = new Shape();
var square = new Square();
square.position; // This will output 1
Run Code Online (Sandbox Code Playgroud)
这一切都对我有意义.
但是,我有一个问题的Angular.js代码似乎与所有这些相关,但做了一件我不理解的事情.它似乎没有处理继承,所以我可以理解为什么会有差异,但我只是好奇为什么他们按照他们的方式编写它.
在Angular.js中,有一个HashMap对象和一个Lexer对象,但它们的定义不同,但似乎是以相同的方式实例化和使用.首先定义Lexer构造函数,然后将原型设置为包含应由Lexer的所有实例共享的方法的对象文字.这一切都有道理.我不明白的是为什么他们指定"构造函数"属性并将其设置为"Lexer",而不是下面的HashMap.
var Lexer = function(options) {
this.options = options;
};
// Notice they specify Lexer as the constructor even though they don't for HashMap below
Lexer.prototype = {
constructor: Lexer, …Run Code Online (Sandbox Code Playgroud) 我需要忽略Java中的所有SSL证书,但我不能让我的生活让它工作.我已经查看了下面列出的以下页面,但似乎没有任何内容可用于每个https链接.
stackoverflow.com/questions/19517538/ignoring-ssl-certificate-in-apache-httpclient-4-3
stackoverflow.com/questions/13470998/ignoring-ssl-validation-in-java
stackoverflow.com/questions/12060250/ignore-ssl-certificate-errors-with-java
stackoverflow.com/questions/2694281/ignore-certificate-errors-when-requesting-a-url-in-java
stackoverflow.com/questions/6681969/java-ignore-certificate-validation
www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/
code.google.com/p/misc-utils/wiki/JavaHttpsUrl
www.exampledepot.8waytrips.com/egs/javax.net.ssl/TrustAll.html
www.obsidianscheduler.com/blog/ignoring-self-signed-certificates-in-java/
java.dzone.com/articles/how-ignore-cert-and-host-name
gist.github.com/henrik242/1510165
Run Code Online (Sandbox Code Playgroud)
我有充分的理由需要这样做所以不要担心,但我真的需要能够做到这一点.基本上,我需要浏览一个内部https链接列表并检查以确保它们仍然有效并且没有损坏的链接.一些链接工作正常,因为Java代码忽略了证书并且可以返回HTTP响应头,但是其他链接只是超时,即使它们在我的Web浏览器中正常工作.所有这些链接都是公司内部链接.
我尝试过使用HttpsURLConnection以及HttpGet和HttpClient.可能还有其他一些我没想到的东西,或者与Java无关的东西可能导致页面超时?我只是想确保链接的URL存在.以下是我得到的例外情况.
使用HttpGet/SSLContextBuilder/PoolingHttpClientConnectionManager:
org.apache.http.conn.HttpHostConnectException: Connect to -removed- [-removed-] failed: Connection timed out: connect
Run Code Online (Sandbox Code Playgroud)
使用X509TrustManager的HttpsUrlConnection:
java.net.ConnectException: Connection timed out: connect
Run Code Online (Sandbox Code Playgroud)
具体来说,我根据上面发布的链接尝试了以下和它的许多变化:
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
// Install the all-trusting trust manager
javax.net.ssl.SSLContext sc = null;
try {
sc = javax.net.ssl.SSLContext.getInstance("TLS");
sc.init(null, …Run Code Online (Sandbox Code Playgroud)