错误提示:javax.servlet.ServletException: Cannot find bean vec in scope requestpackage struts.javabean;
import struts.javabean.Commance;
import java.io.*;
import java.util.Vector;
import java.sql.*;
import struts.dbconnect;
import com.sun.tools.corba.se.idl.toJavaPortable.Compile;
public class FbplRs
{ private Statement stmt=null;
private ResultSet rs=null;
private Connection con=null; public FbplRs(){
 dbconnect db=new dbconnect();             
} public Vector getTitleId(String sql1,int numPages ,int currentPage) throws SQLException
{   int count=numPages;
        Statement stmt = null;
  Vector vec=new Vector();
  try
  {
  dbconnect db=new dbconnect();
 // con=pool.getConnection();
//  stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
// rs=stmt.executeQuery(sql1);
 rs=db.executeQuery(sql1);
 rs.absolute(numPages*(currentPage-1)+1);   while(count>0)
  {        Commance show=new Commance();
  show.setUuid(rs.getString("uuid"));
//  show.setDate(rs.getString("PUBDATE"));
 // show.setContent(rs.getString("CONTENT"));
 // show.setKind(rs.getString("KIND"));
  vec.add(show);
  if(!rs.next()) break;
  count--;
   }
   rs.close();
  }
  catch (SQLException e) { return null;}   con.close();
  return vec;
}
}

解决方案 »

  1.   

    javax.servlet.ServletException: Cannot find bean vec in scope request
    在范围内找不到bean:vec
    vec是个Vector型,从vec里面取数据的时候要强制类型转换,也就是转为Commance类型才能使用。
    不知道是不是这个错误。
      

  2.   

    这是我的COMMANCE
    package struts.javabean;
    public class Commance
    {
    //private String content;
    //private String date;
    //private String kind;
    private String uuid;
    public String getUuid()
    {
    return uuid;
    }
    public void setUuid(String uuid)
    {
    this.uuid=uuid;
    }
    }
      

  3.   

    这是我的ACTION类。package struts.action;
    import java.io.*;
    import java.sql.ResultSet;
    import java.util.Vector;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;import struts.javabean.FbplRs;
    import struts.dbconnect;
    import struts.javabean.Shown;public class FbplAction extends Action { dbconnect db=new dbconnect();
    Shown show=new Shown();
    Vector vec=new Vector(); public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception
    { int i=1;
    int numPages=2;              //第页显示条数
    int nextPage ;
    int upPage;
    String sql;
    String sql1; String pages = request.getParameter("page") ; // String type=request.getParameter("type");
    // String id=request.getParameter("id"); // if(type==null||type.equals(""))
    // {
    // type=(String)request.getAttribute("type");
    // id=(String)request.getAttribute("id");
    // }
    //
    // String sql="select TITLE from "+type+" where ID='"+id+"'";
    // ResultSet rs1=db.executeQuery(sql);
    // if(rs1.next());
    // String title=rs1.getString("TITLE"); int currentPage =(pages==null)?(1):(Integer.parseInt(pages));//当前页 sql = "select count(*) from [table]";
    ResultSet rs = db.executeQuery(sql) ;
    while(rs.next()) i = rs.getInt(1) ; int intPageCount=(i%numPages==0)?(i/numPages):(i/numPages+1);//总页数 if(currentPage>intPageCount) currentPage=intPageCount;
    nextPage = currentPage+1;
    if (nextPage>=intPageCount) nextPage=intPageCount;
    upPage = currentPage-1;
    if (upPage<=1) upPage=1;
    Vector vec=new Vector();
    FbplRs fbrs=new FbplRs(); sql1="select * from [table]";              vec=fbrs.getTitleId(sql1,numPages,currentPage);                        request.setAttribute("vec",vec); request.setAttribute("currentPage",String.valueOf(currentPage));
    request.setAttribute("intPageCount",String.valueOf(intPageCount));
    request.setAttribute("nextpage",String.valueOf(nextPage));
    request.setAttribute("upPage",String.valueOf(upPage)); //request.setAttribute("type",type);
    //request.setAttribute("uuid",uuid);
    //request.setAttribute("title",title);
      System.out.println("SDFSDFSDF");
    return mapping.findForward("success"); }}
      

  4.   

    public String getTitleId(String sql1,int numPages ,int currentPage) throws SQLException
    {   int count=numPages;
            Statement stmt = null;
      Vector vec=new Vector();
      try
      {
      dbconnect db=new dbconnect();
     // con=pool.getConnection();
    //  stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    // rs=stmt.executeQuery(sql1);
     rs=db.executeQuery(sql1);
     rs.absolute(numPages*(currentPage-1)+1);   while(count>0)
      {        Commance show=new Commance();
      show.setUuid(rs.getString("uuid"));
    //  show.setDate(rs.getString("PUBDATE"));
     // show.setContent(rs.getString("CONTENT"));
     // show.setKind(rs.getString("KIND"));
      vec.add(show);
      if(!rs.next()) break;
      count--;
       }
       rs.close();
      }
      catch (SQLException e) { return null;}   con.close();
      return (String)vec;
    }试试?返回类型改了一下
      

  5.   

    nintha(注意休息)我试了, return (String)vec;提示语法有错误啊
      

  6.   

    我写错啦,不好意思,vector返回是个数组,你的返回类型得为String[]吧,关键是看你想要什么
      

  7.   

    Commance show=new Commance();你的commance没有构造函数
      

  8.   

    那就这么写:
    return ((Commance)vec).getUuid();