青鸟租房网站-登录验证 房屋列表显示

建表SQL

--删除表,选择执行,没有以下表就不要运行这些删除表的语句
drop table HOUSE_PICTURE;
drop table HOUSE;
drop table STREET;
drop table DISTRICT;
drop table HOUSE_TYPE;
drop table HOUSE_USER;

--删除序列,选择执行,没有以下序列就不要运行这些删除序列的语句
drop sequence HOUSE_USER_ID ;
drop sequence DISTRICT_ID ;
drop sequence HOUSE_ID ;
drop sequence STREET_ID ;
drop sequence HOUSE_TYPE_ID ;
drop sequence HOUSE_PICTURE_ID ;


--创建表
-- Create table
create table HOUSE_USER
(
  ID        NUMBER(9) not null,
  USERNAME  VARCHAR2(50),
  PASSWORD  VARCHAR2(50),
  TELEPHONE VARCHAR2(15),
  REALNAME  VARCHAR2(50),
  ISADMIN   VARCHAR2(5)
);
alter table HOUSE_USER
  add constraint PRI_HOUSE_USER primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );


create table HOUSE_TYPE
(
  ID   NUMBER(9) not null,
  NAME VARCHAR2(50) not null
);
alter table HOUSE_TYPE
  add constraint PRI_HOUSE_TYPE primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

create table DISTRICT
(
  ID   NUMBER(9) not null,
  NAME VARCHAR2(50) not null
);
alter table DISTRICT
  add constraint PRI_DISTRICT primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

create table STREET
(
  ID          NUMBER(9) not null,
  NAME        VARCHAR2(50),
  DISTRICT_ID NUMBER(9)
);
alter table STREET
  add constraint PRI_STREET primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table STREET
  add constraint STREET_REF_DISTRICT foreign key (DISTRICT_ID)
  references DISTRICT (ID);

create table HOUSE
(
  ID          NUMBER(9) not null,
  USER_ID     NUMBER(9),
  TYPE_ID     NUMBER(9),
  TITLE       VARCHAR2(50),
  DESCRIPTION VARCHAR2(2000),
  PRICE       FLOAT,
  PUBDATE     DATE,
  ADDDATE     DATE,
  FLOORAGE    FLOAT,
  CONTACT     VARCHAR2(100),
  STREET_ID   NUMBER(9)
);
alter table HOUSE
  add constraint PRI_HOUSE primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table HOUSE
  add constraint HOUSE_REF_HOUSE_TYPE foreign key (TYPE_ID)
  references HOUSE_TYPE (ID);
alter table HOUSE
  add constraint HOUSE_REF_HOUSE_USER foreign key (USER_ID)
  references HOUSE_USER (ID);
alter table HOUSE
  add constraint HOUSE_REF_STREET foreign key (STREET_ID)
  references STREET (ID);


create table HOUSE_PICTURE
(
  ID       NUMBER(9) not null,
  HOUSE_ID NUMBER(9),
  TITLE    VARCHAR2(50),
  URL      VARCHAR2(500)
);
alter table HOUSE_PICTURE
  add constraint PRI_HOUSE_PICTURE primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table HOUSE_PICTURE
  add constraint HOUSE_PICTURE_REF_HOUSE foreign key (HOUSE_ID)
  references HOUSE (ID);


--创建序列
create sequence HOUSE_USER_ID increment by 1 start with 10;
create sequence DISTRICT_ID increment by 1 start with 10;
create sequence HOUSE_ID increment by 1 start with 10;
create sequence STREET_ID increment by 1 start with 10;
create sequence HOUSE_TYPE_ID increment by 1 start with 10;
create sequence HOUSE_PICTURE_ID increment by 1 start with 10;

--添加测试数据
insert into HOUSE_USER values (1, 'accp','111111','13888888888','accp','n');
insert into HOUSE_USER values (2, 'jbit','111111','13888888888','jbit','n');
insert into HOUSE_USER values (3, 'admin','111111','13888888888','admin','y');
commit;

insert into HOUSE_TYPE (ID, NAME) values (1, '一室一厅');
insert into HOUSE_TYPE (ID, NAME) values (2, '一室两厅');
insert into HOUSE_TYPE (ID, NAME) values (3, '两室一厅');
insert into HOUSE_TYPE (ID, NAME) values (4, '两室两厅');
insert into HOUSE_TYPE (ID, NAME) values (5, '三室一厅');
insert into HOUSE_TYPE (ID, NAME) values (6, '三室两厅');
insert into HOUSE_TYPE (ID, NAME) values (7, '四室一厅');
insert into HOUSE_TYPE (ID, NAME) values (8, '四室两厅');
insert into HOUSE_TYPE (ID, NAME) values (9, '四十三厅');
commit;

insert into DISTRICT (ID, NAME) values (1, '东城');
insert into DISTRICT (ID, NAME) values (2, '西城');
insert into DISTRICT (ID, NAME) values (3, '石景山');
insert into DISTRICT (ID, NAME) values (4, '朝阳');
insert into DISTRICT (ID, NAME) values (5, '丰台');
insert into DISTRICT (ID, NAME) values (6, '海淀');
commit;

insert into STREET (ID, NAME, DISTRICT_ID) values (1, '知春路', 4);
insert into STREET (ID, NAME, DISTRICT_ID) values (2, '中关村大街', 4);
insert into STREET (ID, NAME, DISTRICT_ID) values (3, '学院路', 4);
insert into STREET (ID, NAME, DISTRICT_ID) values (4, '朝阳路', 6);
commit;

insert into HOUSE values (1,3,1,'好房出租','精装好房,不看后悔',500,to_date('2012-02-02 13:02:40','yyyy-mm-dd hh24:mi:ss'),
to_date('2012-02-02 13:02:40','yyyy-mm-dd hh24:mi:ss'),60.5,'13496659878',1);
insert into HOUSE_PICTURE values (1,1,'','');
commit;

用户接口

package biz;

import entity.HouseUser;

public interface UserBizAware {

    public abstract HouseUser checkUser(HouseUser houseUser);

}

用户接口实现

package biz;

import dao.HouseUserDAO;
import dao.HouseUserware;
import entity.HouseUser;

public class UserBiz implements UserBizAware {
    HouseUserware userDAO = new HouseUserDAO();

    /* (non-Javadoc)
     * @see biz.UserBizware#checkUser(entity.HouseUser)
     */
    @Override
    public HouseUser checkUser(HouseUser houseUser) {
        HouseUser ret = userDAO.findById(houseUser.getId());
        if (ret != null && ret.getPassword().equals(houseUser.getPassword())) {
            return ret;
        } else {
            return null;
        }

    }
}

房屋接口

package biz;

import java.util.List;

import entity.House;

public interface HouseBizAware {
    public List<House> searchAll();
}

房屋接口实现类

package biz;

import java.util.List;

import dao.HouseDAO;
import dao.HouseDAOAware;

import entity.House;

public class HouseBiz implements HouseBizAware {
    HouseDAOAware houseDAO = new HouseDAO();

    @Override
    public List<House> searchAll() {
        return houseDAO.findAll();
    }

}

用户控制层

package action;

import biz.UserBiz;
import biz.UserBizAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entity.HouseUser;

public class UserAction extends ActionSupport {
    private HouseUser houseUser;

    public HouseUser getHouseUser() {
        return houseUser;
    }

    public void setHouseUser(HouseUser houseUser) {
        this.houseUser = houseUser;
    }

    private UserBizAware userBiz = new UserBiz();

    @Override
    public String execute() throws Exception {
        HouseUser ret = userBiz.checkUser(houseUser);
        if (ret != null) {
            // 登录成功 将用户对象保存到session中
            // 两种方式保存,一种方式是解耦式,另一种是非解耦式(耦合式)
            // 1.解耦式
            ActionContext.getContext().getSession().put("loginUser", ret);
            return SUCCESS;
        } else {
            return LOGIN;
        }

    }

}

房屋控制层

package action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import biz.HouseBiz;
import biz.HouseBizAware;

import com.opensymphony.xwork2.ActionSupport;

import entity.House;

public class HouseAction extends ActionSupport {
    // 声明一个业务类型的属性对象
    HouseBizAware houseBiz = new HouseBiz();

    public String execute() {
        // 1.调用业务类对象的方法,获取结果
        List<House> list = houseBiz.searchAll();
        // 将结果保存到Request
        // 2.耦合式
        ServletActionContext.getRequest().setAttribute("houseList", list);
        return SUCCESS;
        // 3.返回页面
    }
}

房屋列表显示

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>

  <body>
    ${loginUser.username }
    <s:property value="#session.loginUser.name"/>
    <!-- 使用标签来访问数据 -->
    <table border=1>
    <!-- 表头 -->
    <tr>
    <td>房屋ID</td>
    <td>房屋所处街道</td>
    <td>房屋的标题</td>
    <td>发布时间</td>
    </tr>
    <!-- 表的主体 -->
    <s:iterator var="house" value="#request.houseList" status="status">
    <s:if test="#status.even">
    <tr bgcolor="yellow">
    </s:if>
    <s:if test="#status.odd">
    <tr bgcolor="gray"></tr>
    </s:if>
    <td><s:property value="#house.id"/></td>
    <td><s:property value="#house.street.name"/></td>
    <td><s:property value="#house.title"/></td>
    <td><s:property value="#house.pubdate"/></td>

    </s:iterator>
    </table>
    -----------------------------------------------------
    <c:forEach items="${houseList }" var="house"><br>
    ${house.id }&nbsp;&nbsp;${house.street.name }&nbsp;&nbsp;${house.title }&nbsp;&nbsp;${house.pubdate }<br>
    </c:forEach>


  </body>
</html>

用户登录

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>

<body>
    <form action="login.action">
        name:<input type="text" name="houseUser.id"><br> password:<input
            type="text" name="houseUser.password"><br> <input type="submit"
            value="submit">
    </form>
</body>
</html>

Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 登录 -->
    <package name="default" namespace="/" extends="struts-default">
        <action name="login" class="action.UserAction">
            <result name="success" type="redirectAction">index</result>
            <result name="login">/login.jsp</result>
        </action>
<!-- 首页 显示房屋信息 -->
        <action name="index" class="action.HouseAction">
            <result>/index.jsp</result>
        </action>
    </package>
</struts>    
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunywz

~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值