我正在为我的应用程序使用Jersey REST Webservices,这就像是一种博客网站(这意味着不需要用户注册或身份验证)
我有一些网络服务,查询数据库并将数据发送到前端。
如您所知,用户可以在浏览器网络选项卡中看到tab服务调用,并手动触发查询
我的问题是,如何保护服务器/服务不被连续攻击(对于手动编写的中断应用程序的循环)
这就是我的服务的样子
@GET
@Produces("text/plain")
public String displaylatestnews() {
String latestnews = "";
PreparedStatement selectpstmt = null;
ResultSet selectRset = null;
Connection conn = null;
String selectsql = "SELECT rssjson from rssfeeds limit 1";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
selectpstmt = conn.prepareStatement(selectsql);
selectRset = selectpstmt.executeQuery();
if (selectRset.next()) {
latestnews = selectRset.getString("rssjson");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
selectRset.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
selectpstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return "jsonCallback(" + latestnews.toString() + ")";
}发布于 2015-10-27 18:19:41
您可以开始避免每次有请求时都创建到mysql的连接,其次,您可以从添加某种缓存开始。即使只持续几秒的高速缓存也可以节省大量的数据库访问。
https://stackoverflow.com/questions/33364897
复制相似问题