zoukankan      html  css  js  c++  java
  • 森林病虫防治系统 (四)

    班级任务:

       依然是资料管理里的三个模块。

    自己的任务:

       实现根据不同的条件实现查询数据,并且跟根据不同条件查询出的数据放在页面表格里。通过查看按钮显示出来更多的数据。

    通过id值查看数据:

    rg:

    完成的任务:

    昨天晚上还是把分页给写出来了。今天完成了数据的插入。

    遇到的问题:

    查询数据?

    部分jsp页面代码:

    1            <form action="/System/selectWorm" method="post">
    2               <ul class="seachform1">
    3                 <li><label>虫害名称</label><input name="w_name" type="text" class="scinput1" /></li>
    4                 <li><label>寄主</label><input name="w_sendHost" type="text" class="scinput1" /></li>
    5                 <li class="sarchbtn"><label>&nbsp;</label><input name="cx" type="submit" class="scbtn" value="查询" /></li>
    6              </ul>
    7            </form>

    执行sql语句;

     1     
     2     @Override
     3     public List<Worm> getWormByInfo( String w_name,String w_sendHost) {
     4         String sql="select * from t_worm where 1=1 ";        
     5             if(w_name!=null&&!(w_name.equals(""))){
     6                 sql+="and w_name like '%"+w_name+"%'";
     7             }                
     8             if(w_sendHost!=null&&!(w_sendHost.equals(""))){
     9                 sql+="and w_sendHost like '%"+w_sendHost+"%'";
    10             }
    11         ResultSet rs=JdbcUtil.executeQuery(sql);
    12         System.out.println(sql);
    13         try {
    14             while(rs.next()){
    15                 Worm w=new Worm();
    16                 w.setW_id(rs.getInt("w_id"));
    17                 w.setW_harm(rs.getString("w_harm"));
    18                 w.setW_name(rs.getString("w_name"));
    19                 w.setW_prevention(rs.getString("w_prevention"));
    20                 w.setW_breed(rs.getString("w_breed"));
    21                 w.setW_naturalEnemy(rs.getString("w_naturalEnemy"));
    22                 w.setW_yongImg(rs.getString("w_yongImg"));
    23                 w.setW_oldImg(rs.getString("w_oldImg"));
    24                 w.setW_sendHost(rs.getString("w_sendHost"));
    25                 list.add(w);    
    26             }
    27 //            pi.setData(list);
    28             return list;
    29         } catch (SQLException e) {
    30             e.printStackTrace();
    31         }finally{
    32             JdbcUtil.close();
    33         }
    34         return list;
    35     }

    servlet代码:

     1 package com.cy.servlet;
     2 
     3 import java.io.IOException;
     4 import java.util.ArrayList;
     5 import java.util.List;
     6 
     7 import javax.servlet.ServletException;
     8 import javax.servlet.http.HttpServlet;
     9 import javax.servlet.http.HttpServletRequest;
    10 import javax.servlet.http.HttpServletResponse;
    11 
    12 import com.cy.dao.IWormDao;
    13 import com.cy.dao.impl.WormDaoImpl;
    14 import com.cy.entity.Worm;
    15 public class SelectWormServlet extends HttpServlet {
    16 
    17     private static final long serialVersionUID = 1L;
    18     
    19     @Override
    20     protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    21             throws ServletException, IOException {
    22         req.setCharacterEncoding("utf-8");
    23         resp.setCharacterEncoding("utf-8");
    24         resp.setContentType("text/html;charset=utf-8");
    25         List<Worm> list=new ArrayList<Worm>();
    26 //        System.out.println("查询");
    27         
    28         String w_name=req.getParameter("w_name");
    29         String w_sendHost=req.getParameter("w_sendHost");
    30 //        System.out.println(w_name);
    31 //        System.out.println(w_sendHost);
    32         
    33         IWormDao iwd=new WormDaoImpl();
    34         list=iwd.getWormByInfo(w_name, w_sendHost);
    35         
    36         System.out.println("++"+list);        
    37         req.setAttribute("pi",list);
    38         
    39         
    40         req.getRequestDispatcher("/web/html/right.jsp").forward(req, resp);
    41         
    42         
    43         
    44     }
    45     
    46     @Override
    47     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    48             throws ServletException, IOException {
    49         doGet(req, resp);
    50     }
    51 
    52 }

    当我点击查询的时候;就报错了;

    在servlet里的打印的数据都是可以打印出来的,

    也就是说我的 req.getRequestDispatcher("/web/html/right.jsp").forward(req, resp);有错。数据就没有传过去;

    可是我在查询全部数据的时候  也是这样的语句,那个都可以传过去的。

    今天晚上看来我又要加班了!

    明天就应该把资料管理的功能全部完成了!

  • 相关阅读:
    Java设计模式の工厂模式
    写Java代码分别使堆溢出,栈溢出
    Java7/8 中的 HashMap 和 ConcurrentHashMap 全解析
    Java集合---ConcurrentHashMap原理分析
    Java 集合类详解
    HashMap详谈以及实现原理
    Java设计模式の代理模式
    Java设计模式の单例模式
    mysql之 navicat表权限设置
    MySQL之You can't specify target table for update in FROM clause解决办法
  • 原文地址:https://www.cnblogs.com/hellokitty1/p/4993120.html
Copyright © 2011-2022 走看看