猿问

在ajax中使用json生成新闻页面

//实体类新闻

public class Easybuy_news {

/**

* 编号

*/

private int en_id;

/**

* 标题

*/

private String en_title;

/**

* 内容

*/

private String en_content;

/**

* 录入时间

*/

private String en_create_time;

public int getEn_id() {

return en_id;

}

public void setEn_id(int enId) {

en_id = enId;

}

public String getEn_title() {

return en_title;

}

public void setEn_title(String enTitle) {

en_title = enTitle;

}

public String getEn_content() {

return en_content;

}

public void setEn_content(String enContent) {

en_content = enContent;

}

public String getEn_create_time() {

return en_create_time;

}

public void setEn_create_time(String enCreateTime) {

en_create_time = enCreateTime;

}

public Easybuy_news() {

// TODO Auto-generated constructor stub

}

public Easybuy_news(int enId, String enTitle, String enContent,

String enCreateTime) {

super();

en_id = enId;

en_title = enTitle;

en_content = enContent;

en_create_time = enCreateTime;

}

}


//servlet类

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {


response.setContentType("text/html");

PrintWriter out = response.getWriter();

 

Easybuy_newsdao  dao=new Easybuy_newsdaoimpl();

Easybuy_news  news=new Easybuy_news();

  List<Easybuy_news> list=dao.findtitle();

    request.setAttribute("list", list);

request.getRequestDispatcher("New.jsp").forward(request, response);

        //response.sendRedirect(contextPath+"New.jsp");

out.flush();

out.close();

}

//jsp页面

<script type="text/javascript">

           $(function(){

               function intinews(){//使用ajax技术获取新闻列表数据

               $.ajax({

                 "url"         :"NewServlet",

                 "type"        :"post",

                 "dataType"    :"json",

                 "success"     :preosn

                 });

               }

               function preosn(data){

                  var $newlist=$("#news").empty();

                  for(var i=0;i<data.length;){

                      $newlist.append(data[i].en_title+"<span>内容:"+data[i].en_content+"</span>")

                  }

               }

               intinews();//执行新闻列表初始化工作

        });

     </script>

  </head>

  

  <body>

     <div id="news">

      

      </div>

  </body>

我这边运行了但它不报错错,可就是在页面上没有加载出来,不知懂怎么回事了

qq_Dreamy_旧城_0
浏览 2161回答 1
1回答

小哈哈v

 data.length后面少了个i++。
随时随地看视频慕课网APP

相关分类

SQL Server
我要回答