我们Bootstrap Modal window用来显示一些通过远程源加载的html.我们通过Bootstrap文档中推荐的方式,通过使用选项remote并传递它来完成此操作url.(如所描述的在这里)
例如:
$('#id').modal({remote:'index.html'});
Run Code Online (Sandbox Code Playgroud)
我的问题:在index.html不可用的情况下是否可以处理错误?
我在文档中没有看到任何答案.
我知道这应该很少发生,但是如果有人连接缓慢或参差不齐,我宁愿向他们展示一个错误,而不是只挂一个空模态.
昨天AWS的RDS下降了 - 我们的数据库也是如此.
发生这种情况时,C3P0会尝试获取数据库连接并挂起.我显然希望我的应用程序在这些实例中返回错误页面,而不是仅仅等待响应.
这是代码的样子:
ComboPooledDataSource db = new ComboPooledDataSource();
...
Connection conn = db.getConnection();
Run Code Online (Sandbox Code Playgroud)
如何设置从c3p0的连接池获取连接的超时?
我以为checkoutTimeout()就是它 - 但事实并非如此.它是"当池耗尽时,客户端调用getConnection()将等待连接被签入或获取的毫秒数." 由于池没有用尽(它只是不可用),这不适用.
我还认为setAcquireRetryAttempts和setAcquireIncrement可以工作 - 但是它们不会因为连接没有失败,所以它只是没有响应.
当我拉动整个堆栈时,这就是它停止的地方:
SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]
SocketInputStream.read(byte[], int, int) line: 129
ReadAheadInputStream.fill(int) line: 113
ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(byte[], int, int) line: 160
ReadAheadInputStream.read(byte[], int, int) line: 188
MysqlIO.readFully(InputStream, byte[], int, int) line: 2428
MysqlIO.reuseAndReadPacket(Buffer, int) line: 2882
MysqlIO.reuseAndReadPacket(Buffer) line: 2871
MysqlIO.checkErrorPacket(int) line: 3414
MysqlIO.sendCommand(int, String, Buffer, boolean, String) line: 1936
MysqlIO.sqlQueryDirect(StatementImpl, String, String, Buffer, int, …Run Code Online (Sandbox Code Playgroud) 我正在创建一个(表现良好的)网络蜘蛛,我注意到一些服务器导致Apache HttpClient给我一个SocketException - 具体来说:
java.net.SocketException: Connection reset
Run Code Online (Sandbox Code Playgroud)
导致这种情况的代码是:
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget); //httpclient is of type HttpClient
} catch (NullPointerException e) {
return;//deep down in apache http sometimes throws a null pointer...
}
Run Code Online (Sandbox Code Playgroud)
对于大多数服务器来说,它很好.但对于其他人来说,它会立即抛出SocketException.
导致立即发生SocketException的站点示例:http://www.bhphotovideo.com/
效果很好(和大多数网站一样):http://www.google.com/
现在,正如您所看到的,www.bhphotovideo.com在Web浏览器中加载正常.当我不使用Apache的HTTP客户端时,它也可以正常加载.(像这样的代码:)
HttpURLConnection c = (HttpURLConnection)url.openConnection();
BufferedInputStream in = new BufferedInputStream(c.getInputStream());
Reader r = new InputStreamReader(in);
int i;
while ((i = r.read()) != -1) {
source.append((char) i);
}
Run Code Online (Sandbox Code Playgroud)
那么,为什么我不只是使用这个代码呢?那么我需要使用Apache的HTTP客户端中的一些关键功能.
有谁知道是什么原因导致某些服务器导致此异常?
迄今为止的研究:
我的本地Mac dev计算机和AWS …
由于某些奇怪的原因,我似乎无法将UTF-8数据添加到我的MySQL数据库中.当我输入一个非拉丁字符时,它存储为?????.其他一切都存储得很好.因此,例如,"这是一个示例®™"存储得很好,但"和中辞典"存储为"????".
连接网址很好:
private DataSource getDB() throws PropertyVetoException {
ComboPooledDataSource db = new ComboPooledDataSource();
db.setDriverClass("com.mysql.jdbc.Driver");
db.setJdbcUrl("jdbc:mysql://domain.com:3306/db?useUnicode=true&characterEncoding=UTF-8");
db.setUser("...");
db.setPassword("...");
return db;
}
Run Code Online (Sandbox Code Playgroud)
我正在按照您的预期使用PreparedStatement,我甚至尝试按照某人的建议输入"set names utf8".
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = db.getConnection();
stmt = conn.prepareStatement("set names utf8");
stmt.execute();
stmt = conn.prepareStatement("set character set utf8");
stmt.execute();
... set title...
stmt = conn.prepareStatement("INSERT INTO Table (title) VALUES (?)");
stmt.setString(1,title);
stmt.execute();
} catch (final SQLException e) {
...
Run Code Online (Sandbox Code Playgroud)
表本身似乎很好.
Default Character Set: utf8
Default Collation: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 D3 显示直方图。
但是,如果我更改 x 域的比例,则会在各个直方图桶的宽度上出现错误。
示例中的代码有效(jsfiddle):
var x = d3.scale.linear()
.domain([0, 1])
.range([0, width]);
Run Code Online (Sandbox Code Playgroud)
但这不是(jsfiddle):
var x = d3.scale.linear()
.domain([0.2, 1])
.range([0, width]);
Run Code Online (Sandbox Code Playgroud)
其他人提到,为了缩放 x 轴,你应该使用这个:
var x = d3.scale.linear()
.domain(d3.extent(data))
.range([0, width]);
Run Code Online (Sandbox Code Playgroud)
但是,这是不可能的,因为尚未创建数据,因为数据需要 x:
var x = d3.scale.linear()
.domain([60, 95])
.range([0, width]);
// Generate a histogram using twenty uniformly-spaced bins.
var data = d3.layout.histogram()
.bins(x.ticks(7))
(values);
Run Code Online (Sandbox Code Playgroud)
那么如果需要 x 来创建数据,我该如何使用数据来创建 x 呢?
请注意,缩放直方图的大边确实有效:
var x = d3.scale.linear()
.domain([0, …Run Code Online (Sandbox Code Playgroud) java ×3
javascript ×2
jdbc ×2
amazon-rds ×1
apache ×1
c3p0 ×1
d3.js ×1
histogram ×1
httpclient ×1
jquery ×1
mysql ×1
sockets ×1
timeout ×1
unicode ×1
utf-8 ×1
web-crawler ×1