在进行ajax调用时,servlet中的get参数始终显示为“null”。

时间:2013-11-26 09:39:55

标签: ajax servlets call

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);

0 个答案:

没有答案