一.listComment.jsp页面的一个超链接:<a href="<s:url action="listcomments" includeParams="none"/>">全部</a>
二.struts.xml内的一个action:<action name="listcomments" class="bookAction" method="listcomments">
<result>/listComment.jsp</result>
</action>
三.bookaction.java里的listcomments方法:public String listcomments()throws Exception{
if(queryMap ==null||queryMap.equals("")){
}else{
String[] str=queryMap.split("~");
this.setQueryName(str[0]);
this.setQueryValue(str[1]);
}
System.out.println("asd"+this.getQueryValue());
int totalRow=ics.getRows(this.getQueryName(),this.getQueryValue());//这里提示java.lang.NullPointerException
System.out.println(totalRow);
pager=pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), totalRow);
this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
this.setTotalRows(String.valueOf(totalRow));
availableItems=ics.getComments(this.getQueryName(),this.getQueryValue(),pager.getPageSize(), pager.getStartRow());
this.setQueryName(this.getQueryName());
this.setQueryValue(this.getQueryValue());
this.setSearchName(this.getQueryName());
this.setSearchValue(this.getQueryValue());
return SUCCESS;
}
四.DAO中getRows的方法:public int getRows(String fieldname, String value) {
String sql="";
if(fieldname==null||fieldname.equals("")||fieldname==null||fieldname.equals(""))
sql="FROM comments ORDER BY commentId";
else
sql="FROM comments where "+fieldname+" like '%"+value+"%'"+"ORDER BY commentId";
List list=this.getHibernateTemplate().find(sql);
return list.size();
}
第一次使用SSH框架,请各位大虾指教!
二.struts.xml内的一个action:<action name="listcomments" class="bookAction" method="listcomments">
<result>/listComment.jsp</result>
</action>
三.bookaction.java里的listcomments方法:public String listcomments()throws Exception{
if(queryMap ==null||queryMap.equals("")){
}else{
String[] str=queryMap.split("~");
this.setQueryName(str[0]);
this.setQueryValue(str[1]);
}
System.out.println("asd"+this.getQueryValue());
int totalRow=ics.getRows(this.getQueryName(),this.getQueryValue());//这里提示java.lang.NullPointerException
System.out.println(totalRow);
pager=pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), totalRow);
this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
this.setTotalRows(String.valueOf(totalRow));
availableItems=ics.getComments(this.getQueryName(),this.getQueryValue(),pager.getPageSize(), pager.getStartRow());
this.setQueryName(this.getQueryName());
this.setQueryValue(this.getQueryValue());
this.setSearchName(this.getQueryName());
this.setSearchValue(this.getQueryValue());
return SUCCESS;
}
四.DAO中getRows的方法:public int getRows(String fieldname, String value) {
String sql="";
if(fieldname==null||fieldname.equals("")||fieldname==null||fieldname.equals(""))
sql="FROM comments ORDER BY commentId";
else
sql="FROM comments where "+fieldname+" like '%"+value+"%'"+"ORDER BY commentId";
List list=this.getHibernateTemplate().find(sql);
return list.size();
}
第一次使用SSH框架,请各位大虾指教!
System.out.println("asd"+this.getQueryValue()); // test...
System.out.println("ics===" + ics);int totalRow=ics.getRows(this.getQueryName(),this.getQueryValue());//这里提示java.lang.NullPointerException 查看抛出来的错误堆栈信息。使用SSH,出现NullPointer,很多情况都是配置文件Ioc的问题
你debug下,看String[] str=queryMap.split("~")中的str[0]str[1],this.getQueryName(),this.getQueryValue()这几个是不是出现null了