车辆广告网站搜索功能使用JSP,Java和MySQL

时间:2014-08-09 12:27:13

标签: java mysql jsp servlets

我正在尝试制作汽车广告网站,如autotrader或ebay。我正在为数据库使用html,css,jsp,java和mysql。我在系统的最后几页遇到问题。基本上我希望用户能够通过表单搜索车辆(广告),然后在Servlet处理后将它们定向到结果页面。在results_page上,他们可以选择要点击的广告。顺便说一句,我是初学者,到目前为止,我已经尝试过我所能达到的目标。我不知道最后一页尝试谷歌搜索和研究,但无法找到任何关于点击结果(来自result_page的广告)以获取有关它的更多细节(例如制作,模型等)并在单独显示它(advert_page)。使用html5lightbox查看图像和视频,它们存储在本地文件夹中,因此只有路径存储在数据库中。

来自数据库的广告表

Table structure for table `advert`
--

CREATE TABLE IF NOT EXISTS `advert` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `title` text COLLATE latin1_bin NOT NULL,
  `dealer_name` int(15) NOT NULL,
  `make` text COLLATE latin1_bin NOT NULL,
  `model` text COLLATE latin1_bin NOT NULL,
  `year` year(4) NOT NULL,
  `price` text COLLATE latin1_bin NOT NULL,
  `condition` text COLLATE latin1_bin NOT NULL,
  `image1` blob NOT NULL,
  `image2` blob NOT NULL,
  `image3` blob NOT NULL,
  `image4` blob NOT NULL,
  `video1` blob NOT NULL,
  `phone_number` text COLLATE latin1_bin NOT NULL,
  `type` text CHARACTER SET cp1250 COLLATE cp1250_bin NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

ResultsServlet.java

Statement st;
        try {
            Class.forName(driver).newInstance();
            conn = DriverManager.getConnection(url + dbName, userName, password);
            System.out.println("Connected!");
            String q = request.getParameter("q"); //search entry from user via form 

            ArrayList al = null:
            ArrayList advert_list = new ArrayList();
            String query = "SELECT title, price, image1 FROM advert WHERE title, make,   `model LIKE '%%' "";` //sort according to lkeness of search entry entered by user

            System.out.println("query " + query);
            st = conn.createStatement();
            ResultSet rs = st.executeQuery(query);

            while (rs.next()) {
                al = new ArrayList();

//                out.println(rs.getString(1));
//                out.println(rs.getString(2));
//                out.println(rs.getString(3));
//                out.println(rs.getString(4));
                al.add(rs.getString(1));
                al.add(rs.getString(2));
                al.add(rs.getString(3));
                al.add(rs.getString(4));

                System.out.println("al :: " + al);
                advert_list.add(al);
            }

            request.setAttribute("adList", advert_list);
            RequestDispatcher view = request.getRequestDispatcher("/searchview.jsp");
            view.forward(request, response);
            conn.close();
            System.out.println("Disconnected!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

      /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

results_page.jsp

<head>
    <title>Search Results</title>

<script type="text/javascript" src="html5lightbox/jquery.js"></script>
<script type="text/javascript" src="html5lightbox/html5lightbox.js"></script>

</head>
    <body>

<div class="html5lightbox">
    <!-- need fetch only one image per advert to show the picture of the car ->
    <!-- so there should be  images corresponding to the arrays of results or adverts and the advert `details` ->
        </div>

<div class="advert_details">
<!--need to fetch title of advert and price  ->

    </div>
</body>
</html>

**FetchAdvertServlet.java**

//don't have an idea where to start
// need to fetch images  and details according to link pressed by the user 

**advert.jsp**

<!-- also don't have an idea, need loads of help or ideas ->
<!-- if there is a way for the page to fetch the advert's details by 

0 个答案:

没有答案