VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 网站开发 > JavaScript >
  • JavaScript教程之大项目之网上书城(三)——主页(2)

xin = "#x" + i; $(xin).html(data); }); }; }); //通过点击b1,b2,b3,b4,配合以特殊的查询方式,将前8的热门书展示在页面上。 $("#b1").click(function(){ $.post("../ReMen?page=1",function(data){ var code=data; code=code.split("#"); $("#a1").html(code[0]); $("#a2").html(code[1]); }); }); $("#b2").click(function(){ $.post("../ReMen?page=2",function(data){ var code=data; code=code.split("#"); $("#a1").html(code[0]); $("#a2").html(code[1]); }); }); $("#b3").click(function(){ $.post("../ReMen?page=3",function(data){ var code=data; code=code.split("#"); $("#a1").html(code[0]); $("#a2").html(code[1]); }); }); $("#b4").click(function(){ $.post("../ReMen?page=4",function(data){ var code=data; code=code.split("#"); $("#a1").html(code[0]); $("#a2").html(code[1]); }); }); });

3.ReMenServlet

代码

package cn.edu.bdu.mc.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ReMenServlet
 */
@WebServlet("/ReMen")
public class ReMenServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReMenServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int page = Integer.parseInt(request.getParameter("page"));
        /*
        List<Book> list;
        BookService bookService = new BookService();
        //拟定写一个BookService类,其中有findBookReMen方法,可以根据页数查找热门图书信息,每页只显示2个。
        list = bookService.findBookReMen(page);
        String bookNames = list[0].getName()+"#"+list[1].getName();
        //将书名返回。
        response.getWriter().write(bookNames);
        */
        //测试---成功!!!
        if(page==1) {
            response.getWriter().print("好书#真是好书啊");
        }else {
            response.getWriter().print("全都是#好书!");
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

4.XinShuServlet

代码

package cn.edu.bdu.mc.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class XinShuServlet
 */
@WebServlet("/XinShu")
public class XinShuServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XinShuServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //通过js动态从数据库中取图片。
        int shu = Integer.parseInt(request.getParameter("shu"));
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

5.XinShuMingServlet

代码

package cn.edu.bdu.mc.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class XinShuServlet
 */
@WebServlet("/XinShuMing")
public class XinShuMingServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XinShuMingServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //通过js动态从数据库中取书名,以及书的路径,写成一个a标签。
        int shu = Integer.parseInt(request.getParameter("shu"));
        //待填空:类别、书的二级id、书名
        String html = "<a href='${pageContext.request.contextPath}/client/"+"类别/"+"shu?er_id="+"书的二级id"+"' style='font-size:16px'>"+"书名"+"</a>";
        response.getWriter().print(html);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

相关教程