struts.xml
:Struts2的,我有一個NullPointerException異常報告
<package name="backpower" namespace="/backpower" extends="struts-default">
<default-interceptor-ref name="defaultStack"></default-interceptor-ref>
<!-- backup battery manager -->
<action name="backpower" class="com.cps.backpower.action.BackpowerAction">
<result name="addBattery">/WEB-INF/views/backpower/info/addBattery.jsp</result>
<result name="editBattery">/WEB-INF/views/backpower/info/editBattery.jsp</result>
<result>/WEB-INF/views/backpower/info/list.jsp</result>
</action>
</package>
add.jsp
:
<div class="form-actions">
<button name="method:save" type="submit" class="btn btn-primary">
save
</button>
<button type="reset" class="btn">
reset
</button>
</div>
我BackpowerAction
類
public class BackpowerAction extends BaseManageAction{
private static final long serialVersionUID=1L;
public BackpowerService backpowerService;
public PaginationSupport backpowerPagination;
public PageTip pageTip;
public BackpowerInfo backpowerInfo;
public Long id;
public String execute() throws Exception{
return search();
}
public String search(){
String hql="from BackpowerInfo where 1=1";
backpowerPagination=backpowerService.getPage(hql,getPageNo(),getPageSize());
return SUCCESS;
}
public void setBackpowerInfo(BackpowerInfo backpowerInfo){
this.backpowerInfo=backpowerInfo;
}
public String add(){
return "addBattery";
}
public String save() {
if (backpowerInfo.getId() == null) {
try {
backpowerService.save(backpowerInfo);
return SUCCESS;
} catch (Exception e) {
return add();
}
} else {
try {
backpowerService.update(backpowerInfo.getId(),backpowerInfo.getName(),backpowerInfo.getLocation(),backpowerInfo.getManager());
pageTip.setOk(true);
pageTip.setTip("修改用戶信息成功");
return search();
} catch (Exception e) {
e.printStackTrace();
pageTip.setOk(false);
pageTip.setTip("修改用戶信息失敗");
return edit();
}
}
}
public String edit() {
backpowerInfo=backpowerService.findById(getId());
return "editBattery";
}
public String del() throws Exception {
try {
backpowerService.delete(getId());
pageTip.setOk(true);
pageTip.setTip("刪除成功");
} catch (Exception e) {
pageTip.setOk(false);
pageTip.setTip("刪除失敗");
}
return search();
}
public BackpowerInfo getBackpowerInfo(){
return backpowerInfo;
}
public PaginationSupport getBackpowerPagination(){
return backpowerPagination;
}
public void setBackpowerPagination(PaginationSupport backpowerPagination){
this.backpowerPagination=backpowerPagination;
}
public BackpowerService getBackpowerService(){
return backpowerService;
}
public void setBackpowerService(BackpowerService backpowerService){
this.backpowerService=backpowerService;
}
public PageTip getPageTip(){
return pageTip;
}
public void setPageTip(PageTip pageTip){
this.pageTip=pageTip;
}
public long getId(){
return id;
}
public void setId(long id){
this.id=id;
}
}
顯示java.lang.NullPointerException
com.cps.backpower.action.BackpowerAction.save(BackpowerAction.java:39)
當我點擊保存網頁上的按鈕,它提供了Struts2的問題報告,我錯在哪裏,我該如何糾正?
使用能否請您發佈完整的堆棧跟蹤的名字嗎? – reto
你可以發佈struts錯誤嗎?空指針可能會拋出* backpowerService.update(backpowerInfo.getId(),backpowerInfo.getName(),backpowerInfo.getLocation(),backpowerInfo.getManager()); *因爲您不檢查值。 –
BackpowerAction.java第39行的代碼是什麼? – orique