enter code here
Javascript
$(document).ready(function(){
var link="http://feeds.feedburner.com/techcrunch/startups";
$.ajax({
type:"GET",
url: "/FeedAction",
data:"links="+link,
success:function(data){
alert(data);
},
error : function(errorData){
alert("Some error occurred while processing the request");
}
});
});
下面是我正在尝试getparameters(“links”)的servlet,它一直抛出null,我正在尝试从“links”获取参数并将其设置在where子句中以从数据库生成数据。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url=request.getParameter("links");
System.out.println(url);
List<DataVO> users=new ArrayList<DataVO>();
Connection connection = null;
ResultSet resultset = null;
PreparedStatement preparedstatement=null;
try {
connection=ConnectionManager.getConnection();
preparedstatement=connection.prepareStatement("select description,date,link from post where feedlink in('"+url+"')");
resultset=preparedstatement.executeQuery();
while(resultset.next()){
DataVO user=new DataVO();
user.setDescription(resultset.getString("description"));
user.setDate(resultset.getString("date"));
user.setLink(resultset.getString("link"));
users.add(user);
}
} catch (SQLException e) {
try {
connection.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
preparedstatement.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
resultset.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
}
request.setAttribute("feed", users);
request.getRequestDispatcher("FeedAction.jsp").forward(request, response);