IllegalStateException问题
|
我面临java.lang.IllegalStateException的问题...
我不知道为什么在执行代码时会抛出该代码...我将代码粘贴到下面...
我正在使用Hibernate和Struts框架...
package dao;
import com.opensymphony.xwork2.ActionSupport;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
import org.apache.struts2.ServletActionContext;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import persistence.HibernateUtil;
import pojo.Photo;
public class GetImages extends ActionSupport{
int limit;
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
@Override
public String execute() throws Exception{
ServletActionContext.getResponse().setContentType(\"text/html\");
PrintWriter pw = ServletActionContext.getResponse().getWriter();
SessionFactory sf = HibernateUtil.getSf();
Session ss = sf.openSession();
String returnText = \"\";
Criteria cr = ss.createCriteria(Photo.class);
cr.addOrder(Order.desc(\"uploadTime\"));
cr.setFirstResult(0);
cr.setMaxResults(getLimit());
List<Photo> li = cr.list();
Iterator<Photo> it = li.iterator();
if(!(it.hasNext())){
return ERROR;
}
while(it.hasNext()){
Photo p = it.next();
returnText = returnText + p.getPhotoName().trim()+\"\\\"\\\"\"+(String.valueOf(p.getUploadTime())).trim()+\"\\\"\\\"\"+p.getTitle().trim()+\"\\\"\\\"\"+p.getDescription().trim()+ \"\\\'\\\'\\n\";
}
returnText = returnText.substring(0, returnText.length()-2);
JOptionPane.showMessageDialog(null, returnText);
pw.println(returnText);
pw.flush();
pw.close();
ss.close();
sf.close();
return SUCCESS;
}
}
没有找到相关结果
已邀请:
1 个回复
屑凉赦