日期:2014-05-17  浏览次数:20989 次

数据显示
用struts2 为什么从数据库中读取的数据在页面中无法显示
从数据库中读取问题信息的代码如下:
package teachinves.db;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import teachinves.bean.question;
import teachinves.bean.teacher;


import DBConn.Odb;



public class lessonDAO {
Odb odb=new Odb();
 
public List<question> allquestion(){
List<question> list=new ArrayList<question>();
String sql="select * from QUESTION_LIST";
try{
PreparedStatement ps=odb.getConnection().prepareStatement(sql);
ResultSet rs=ps.executeQuery(sql);
while(rs.next()){
question que=new question();
que.setVquestionid(rs.getString("vquestionid"));
que.setVquestiontitle(rs.getString("vquestiontitle"));
que.setVquestioncontent(rs.getString("vquestioncontent"));
que.setDquestiontime(rs.getDate("dquestiontime"));
que.setVlessonid(rs.getString("vlessonid"));
que.setVteacherid(rs.getString("vteacherid"));
que.setVquizstudentid(rs.getString("vquizstudentid"));
que.setVlabelid(rs.getString("vlabelid"));
que.setIstateid(rs.getInt("istateid"));
que.setVquestionstatid(rs.getString("vquestionstatid"));
que.setVmerat(rs.getInt("vmerat"));
que.setVdescription(rs.getString("vdescription"));
que.setVevaluate(rs.getString("vevaluate"));
que.setVsuggestion(rs.getString("vsuggestion"));
list.add(que);

 
}
}catch (Exception e){
e.printStackTrace();
}finally{
odb.close();
}
return list;
 
}
}


其中的action代码如下:
package teacher.action;

import java.util.ArrayList;
import java.util.List;

import javax.management.Query;

import DBConn.test;

import com.bean.statistic;
import com.opensymphony.xwork2.ActionSupport;

import teachinves.bean.question;
import teachinves.bean.teacher;
import teachinves.db.lessonDAO;
import teachinves.db.statisticDao;

public class QuestionAction extends ActionSupport {
  private static final String SUCCESS = null;
  private List<question> allquestion;
 

public List<question> getAllquestion() {
return allquestion;
}

public void setAllquestion(List<question> allquestion) {
this.allquestion = allquestion;
}
  public String excute(){
  lessonDAO ld=new lessonDAO();
   
  ld.allquestion();
 
  return SUCCESS;
  }
   
}

struts.xml文件配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
  <include file="struts-default.xml"></include> 
  <package name="struts2" extends="struts-default" >  
  <action name="allquestion" class="teacher.action.QuestionAction" method="getAllquestion">
  <result name="success">/index.jsp</result>
  </action>