qq_24855259
qq_24855259
2016-07-12 11:10

一个JSP界面有多个按钮 对应一个servlet 其中一个按钮实现多表查询并显示出查询数据

20

一个JSP界面有多个按钮 对应一个servlet 其中一个按钮实现多表查询并显示出查询数据 跳转到JSP界面没有显示出任何结果
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html");
System.out.println("111111111");
PrintWriter out = response.getWriter();
String value=(String)request.getParameter("btnType");
if(value.equals("账单")){
User user = (User)request.getSession().getAttribute("userNow");
String name = user.getUser();//获取房东ID
AccountCheck ac = new AccountCheck();
request.setAttribute( "ValueA",ac.getAllAccount(name));
response.sendRedirect("zhangdan.jsp");
//request.getRequestDispatcher("zhangdan.jsp").forward(request,response);

        }
        if(value.equals("闲置房号")){

        }
        if(value.equals("即将到期的租客")){

        }
    }
        数据库操作:
        //查询所有账单的方法
    public List getAllAccount(String name){
        List list=new ArrayList();
        try {
            url="jdbc:sqlserver://localhost:1433;DatabaseName=rh";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载驱动
            Connection con = DriverManager.getConnection(url, "rh", "123");//获得连接对象
          //查询语句
         String sql="select 姓名,house.地址,租金,起始日期,终止日期 from house,renthouse,userinfro where house.代号=renthouse.代号 and renthouse.身份证号码=userinfro.身份证号码 and renthouse='"+name+"'";
         //stmt.setString(1, name);
         stmt = con.prepareStatement(sql);
         System.out.println(sql);
        ResultSet rs = stmt.executeQuery(sql);
            //循环结果集,存储在list里面
            while(rs.next()){
                list.add(rs.getString("1"));
                list.add(rs.getString("2"));
                list.add(rs.getString("3"));
                list.add(rs.getString("4"));
                list.add(rs.getString("5"));
                for(int i = 0;i<list.size();i++){
                  System.out.println(list.get(i));
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //返回List
        return list;    
    }

}
from提交










<br><br>
   <input type='submit' btnType="action4"   value=租客信息 style="width:80px;height:40px;background-color:#FFFFFF" onclick="document.getElementById('btnType').value=this.type;this.from.submint()"> <br><br> 
</div>


显示查询结果的JSP界面

"+(String)list.get(i)+""+(String)list.get(i+1)+"/tr>"); %>
租客姓名 地址 租金 租房日期 租房截至日期
"+(String)list.get(i+1)+""+(String)list.get(i+1)+" "+(String)list.get(i+1)+" "+(String)list.get(i+1)+"

在线等

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答