//實體類新聞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技術獲取新聞列表數(shù)據(jù)? ? ? ? ? ? ? ?$.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();//執(zhí)行新聞列表初始化工作? ? ? ? });? ? ?</script>? </head>??? <body>? ? ?<div id="news">? ? ??? ? ? </div>? </body>我這邊運行了但它不報錯錯,可就是在頁面上沒有加載出來,不知懂怎么回事了
在ajax中使用json生成新聞頁面
qq_Dreamy_舊城_0
2017-07-12 12:12:12