67,513
社区成员
发帖
与我相关
我的任务
分享
....此处省略部分代码....
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<%@ page import="realEstate.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="db" class="realEstate.DataSource" scope="session"/>
<jsp:useBean id="my_search" class="realEstate.Search" scope="session"/>
<jsp:setProperty name="my_search" property="*" />
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search Result</title>
</head>
<body>
<%
ArrayList<Property> resultList = my_search.search(db);
%>
...此处省略部分代码....
</body>
</html>
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
FileInputStream fStream = new FileInputStream("/home/wesley/rent.xml");
还是用这样的吧Configuration().configure().buildSessionFactory();
新的貌似不稳定,有问题
<% request.setAttribute("db", db); %>
<% request.setAttribute("my_search", my_search); %>
...前面import部分省略...
/**
* @author TPOF314
*/
public class DataSource {
private Document domTree;
private ArrayList<Property> properties;
public DataSource() throws ParseException {
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
FileInputStream fStream = new FileInputStream("/home/wesley/rent.xml");
domTree = (Document) builder.parse(fStream);
properties = new ArrayList<Property>();
// Fill data
Node root = domTree.getFirstChild();
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node propNode = children.item(i);
properties.add(DataSource.getProperty(propNode));
}
} catch (FileNotFoundException ex) {
Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
} catch (SAXException ex) {
Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
}
}
private boolean checkSuburb(Property prop, String suburbs[]) {
for (int i=0; i<suburbs.length; i++) {
if (prop.getSuburb().equals(suburbs[i])) {
return true;
}
}
return false;
}
public ArrayList<Property> searchBySuburb(String suburb) {
System.out.println("Suburb: " + suburb);
if (suburb.equals("Any") || suburb.equals("")) {
return (ArrayList)properties.clone();
}
else {
ArrayList<Property> resultSet = new ArrayList<Property>();
String suburbs[] = suburb.split("; ");
for (int i=0; i<properties.size(); i++) {
if (checkSuburb(properties.get(i), suburbs)) {
resultSet.add(properties.get(i));
}
}
return resultSet;
}
}
public void filterByType(ArrayList<Property> propList, String type) {
if (!type.equals("Any")) {
int len = propList.size();
for (int i=len-1; i>=0; i--) {
Property prop = propList.get(i);
if (!prop.getType().equals(type)) {
propList.remove(i);
}
}
}
}
public void filterByBedroom(ArrayList<Property> propList, int bedroom) {
....中间代码和前面类似,省略....
}
public void filterByRent(ArrayList<Property> propList, int rent) {
....中间代码和前面类似,省略....
}
public void filterByDate(ArrayList<Property> propList) {
....中间代码和前面类似,省略....
}
public Document getDomTree() {
return this.domTree;
}
public ArrayList<Property> getProperty() {
return (ArrayList)this.properties.clone();
}
private static Property getProperty(Node node) throws ParseException {
....中间代码省略...;
}
}