解决方案 »
- 请教一下JSF里的dataScroller分页问题
- 请教!jsp如何判断用户按的是哪一条记录的“派遣” 或 “删除”按钮
- 大家帮忙看看下面的链接是什么意思
- HttpClient 中的https应该怎么办!!!!(高分顶着有分)
- 高手们请告诉我这是什么技术:
- struts1和struts2 同时应用会有冲突吗
- 字符串比较问题,谁能帮忙解释一下?小第先谢啦~
- 请问我将ArrayList中数据用<LOGIC:iterate>来显示,为何重复显示最后一条数据。
- sun公司的资深工程师给我们培训,但是我们!跟贴有分!
- springBoot 静态资源放在resource下,静态目录meta-info文件内不可访问
- 使用hibernate最好使用哪种查询方式??
- 如何在spring配置多个数据源
realEstate.DataSource.searchBySuburb(DataSource.java:71)
realEstate.Search.search(Search.java:55)
org.apache.jsp.searchResult_jsp._jspService(searchResult_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这些是错误提示~~
请各位高手过目。
这个类的 71行出现空指针,你可以debug看下是什么参数为空
这个问题对初学者蛮常见的
尤其是想在用同一个jsp文件同时发送和接收数据的时候有几个地方楼主可以注意一下
1 在servlet里有没有设置request.setAttribute
2 javaBean文件有没有设置初始值(单纯的提取数据可能没事,但是如果牵扯到逻辑业务没有初始值很容易空指针)
3 如果楼主在javaBean文件里设置了有一个或多个参数的构造函数,注意在调用的时候哪怕是写一个没有内容的构造函数也一定要补上,否则也容易出现错误希望对你有所帮助
以上
...前面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 {
....中间代码省略...;
}
}
谢谢了,第2点和第3点我都注意到了,也检查过了。其中第3点应该不是什么大问题,因为我的全部类都只有一个构造函数。
第二点,我已经在构造函数里面把初始值设过了,应该也不是什么大问题。
第一点有点不太明白。能帮我具体讲一下request.setAttribute的用处吗?是不是一开始要加这么两句:<% request.setAttribute("db", db); %>
<% request.setAttribute("my_search", my_search); %>我试了一下,貌似没什么用~~
DocumentBuilder builder = builderFactory.newDocumentBuilder();
FileInputStream fStream = new FileInputStream("/home/wesley/rent.xml");还是用这样的吧Configuration().configure().buildSessionFactory();
新的貌似不稳定,有问题