当前位置: 代码迷 >> J2EE >> struts2+hibernate整合,出现空指针异常,求人帮帮忙
  详细解决方案

struts2+hibernate整合,出现空指针异常,求人帮帮忙

热度:308   发布时间:2016-04-17 23:43:34.0
struts2+hibernate整合,出现空指针错误,求人帮帮忙



XsAction:
package org.action;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;



import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.dao.imp.KcDao;
import org.dao.imp.KcDaoImp;
import org.dao.imp.XsDao;
import org.dao.imp.XsDaoImp;
import org.dao.imp.ZyDao;
import org.dao.imp.ZyDaoImp;
import org.model.*;

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

public class XsAction  extends ActionSupport{
KcDao kcDao;
XsDao xsDao;
private Xsb xs;
private Kcb kcb;
private File zpFile;
private Zyb zyb;
public File getZpFile(){
return zpFile;
}
public void setZpFile(File zpFile){
this.zpFile=zpFile;
}
public Kcb getKcb(){
return kcb;
}
public void setKcb(Kcb kcb){
this.kcb=kcb;
}
public Zyb getZyb(){
return zyb;
}
public void setZyb(Zyb zyb){
this.zyb=zyb;
}
public Xsb getXsb(){
return xs;
}
public void setXsb(Xsb xs){
this.xs=xs;
}
public String execute() throws Exception{
Map session=(Map)ActionContext.getContext().getSession();
Dlb user=(Dlb)session.get("user");
xsDao=new XsDaoImp();
Xsb xs=xsDao.getOneXs(user.getXh());
Map request=(Map)ActionContext.getContext().get("request");
request.put("xs", xs);
return SUCCESS;

}
public String getImage() throws Exception{
xsDao=new XsDaoImp();
byte[] zp=xsDao.getOneXs(xs.getXh()).getZp();
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("image/jpeg");
ServletOutputStream os=response.getOutputStream();
if(zp!=null&&zp.length>0){
for(int i=0;i<zp.length;i++){
os.write(zp[i]);
}
}
return NONE;

}
public String updateXsInfo() throws Exception{
Map session=(Map)ActionContext.getContext().getSession();
Dlb user=(Dlb)session.get("user");
xsDao=new XsDaoImp();
ZyDao zyDao=new ZyDaoImp();
List zys=zyDao.getAll();
Xsb xs=xsDao.getOneXs(user.getXh());
Map request=(Map)ActionContext.getContext().get("request");
request.put("zys", zys);
request.put("xs", xs);
return SUCCESS;



}
public String updateXs() throws Exception{
xsDao=new XsDaoImp();
ZyDao zyDao=new ZyDaoImp();
Xsb stu=new Xsb();
stu.setXh(xs.getXh()); 102行
Set list=xsDao.getOneXs(xs.getXh()).getKcs();
stu.setKcs(list);
stu.setXm(xs.getXm());
stu.setXb(xs.getXb());
stu.setCssj(xs.getCssj());
stu.setZxf(xs.getZxf());
stu.setBz(xs.getBz());
Zyb zy=zyDao.getOneZy(zyb.getId());
stu.setZyb(zy);
if(this.getZpFile()!=null){
FileInputStream fis=new FileInputStream(this.getZpFile());
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
stu.setZp(buffer);
}
xsDao.update(stu);

return SUCCESS;

}
public String getXsKcs() throws Exception{
Map session=(Map)ActionContext.getContext().getSession();
Dlb user=(Dlb)session.get("user");
xsDao=new XsDaoImp();
String xh=user.getXh();
Xsb xsb=xsDao.getOneXs(xh);
Set list=xsb.getKcs();
Map request=(Map)ActionContext.getContext().get("request");
request.put("list", list);
return SUCCESS;


}
public String deleteKc() throws Exception{
Map session=(Map)ActionContext.getContext().getSession();
String xh=((Dlb)session.get("user")).getXh();
xsDao=new XsDaoImp();
Xsb xs2=xsDao.getOneXs(xh);
Set list=xs2.getKcs();
Iterator iter=list.iterator();
while(iter.hasNext()){
Kcb kc2=(Kcb)iter.next();
if(kc2.getKch().equals(kcb.getKch())){
iter.remove();
}
}
xs2.setKcs(list);
xsDao.update(xs2);
return SUCCESS;
}
public String selectKc() throws Exception{
Map session=(Map)ActionContext.getContext().getSession();
String xh=((Dlb)session.get("user")).getXh();
xsDao=new XsDaoImp();
Xsb xs3=xsDao.getOneXs(xh);
Set list=xs3.getKcs();
Iterator iter=list.iterator();
while(iter.hasNext()){
Kcb kc3=(Kcb)iter.next();
if(kc3.getKch().equals(kcb.getKch())){
return ERROR;
}



}
            list.add(new KcDaoImp().getOneKc(kcb.getKch()));

xs3.setKcs(list);
  相关解决方案