我遇到了 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;
}
}
答案 0 :(得分:1)
https://struts.apache.org/release/2.1.x/docs/result-configuration.html
这可能会有所帮助......我已经解决了自己的问题......:P:P:P