<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index" class="com.mobile_bbs.action.Doindex">
<result name="success">/index.jsp
            </result>
</action>
这是我的部分struts2.xml,配置默认action。为什么只是显示一个静态页面,而没有执行一些数据交互?
(我的action里面是list=IndexDAO.getFCname();从数据库里取一串名字放在list里面)

解决方案 »

  1.   

    没明白问题……要干什么在com.mobile_bbs.action.Doindex里写啊
      

  2.   

    把你的Action execute() method贴出来看下
      

  3.   

    看你页面有没有加载指定啊  再说你的method呢? 看看访问的是哪个方法啊
      

  4.   

    跟踪调试一下,页面有没进入action先。如果没有就是路径有问题。
      

  5.   

    <default-action-ref name="index"></default-action-ref>好像是有BUG的吧,就是说它只能执行简单的视图而不能通过ACTION完成与数据库的交互。是吗?
      

  6.   

    我的ACTION
    package com.mobile_bbs.action;import java.sql.SQLException;
    import java.util.List;
    import com.mobile_bbs.DAO.IndexDAO;
    import com.opensymphony.xwork2.ActionSupport;public class Doindex extends ActionSupport { private List<String> list=null;
    private int fbnum;
    private String[] str;
    private int fbtn;
    private String fbau;
    private int fbid;
    public String excute() throws SQLException
    {   
    list=IndexDAO.getFCname();
    fbnum=IndexDAO.getFBnumber(fbid);
    str=IndexDAO.getFBlast(fbid);
    fbtn=IndexDAO.getFBtoday(fbid);
    fbau=IndexDAO.getFBauthor(fbid);
    return SUCCESS;

    }
    public List<String> getList() {
    return list;
    }
    public void setList(List<String> list) {
    this.list = list;
    }
    public int getFbnum() {
    return fbnum;
    }
    public void setFbnum(int fbnum) {
    this.fbnum = fbnum;
    }
    public String[] getStr() {
    return str;
    }
    public void setStr(String[] str) {
    this.str = str;
    }

    public String getFbau() {
    return fbau;
    }
    public void setFbau(String fbau) {
    this.fbau = fbau;
    }
    public int getFbtn() {
    return fbtn;
    }
    public void setFbtn(int fbtn) {
    this.fbtn = fbtn;
    }
    public int getFbid() {
    return fbid;
    }
    public void setFbid(int fbid) {
    this.fbid = fbid;
    }

    }
    我的DAO
    package com.mobile_bbs.DAO;import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;import com.mobile_bbs.util.DbPool;public class IndexDAO {
        //列出类目的名字
    public static List<String> getFCname() throws SQLException
    {  
    DbPool db=DbPool.getInstance();
    Connection conn=db.getConnection();
    List<String> list=new ArrayList<String>();
    String sql="select FCname from Forum_Categories";
    PreparedStatement pst=conn.prepareStatement(sql);
    ResultSet rs= pst.executeQuery();
    while(rs.next())
    {
    list.add(rs.getString("FCname"));
    }
    rs.close();
    pst.close();
    conn.close();
    return list;

    }
    //指定版块主题的数量
    public static int getFBnumber(int fbid) throws SQLException
    {   DbPool db=DbPool.getInstance();
        Connection conn=db.getConnection();
        int num=0;
        String sql="select count(FBid) from Forum_Board where FBid= ? ";
        PreparedStatement pst=conn.prepareStatement(sql);
        pst.setInt(1,fbid);
        ResultSet rs=pst.executeQuery();
        num=rs.getInt(1);
        rs.close();
        pst.close();
        conn.close();
    return num;

    }
    //最后发主题帖的时间和作者
    public static String[] getFBlast(int fbid) throws SQLException
    {   DbPool db=DbPool.getInstance();
        Connection conn=db.getConnection();
        String sql="select top 1 * from Forum_Topic where FBid= ? order by FTdate desc";
        PreparedStatement pst=conn.prepareStatement(sql);
        pst.setInt(1, fbid);
        ResultSet rs=pst.executeQuery();
       
        String[] st=null;
        while(rs.next())
        { st=new String[2];
          st[0]=rs.getString("FTdate");
          st[1]=rs.getString("FTauthor");
        }
        rs.close();
        pst.close();
        conn.close();
        return st;
    }
    //今天发的主题数
    public static int getFBtoday(int fbid) throws SQLException
    {
    DbPool db=DbPool.getInstance();
    Connection conn=db.getConnection();
    String sql="select count(*) from Forum_Topics where (datediff(day,FTdate,getdate())=0) and FBid = ?";
    PreparedStatement pst=conn.prepareStatement(sql);
    pst.setInt(1, fbid);
    ResultSet rs=pst.executeQuery();
    int num=rs.getInt(1);
    rs.close();
    pst.close();
    conn.close();
    return num;
    }
    //版主
    public static String getFBauthor(int fbid) throws SQLException
    {
    DbPool db=DbPool.getInstance();
    Connection conn=db.getConnection();
    String sql="select FBauthor from Forum_Board where FBid= ? ";
    PreparedStatement pst=conn.prepareStatement(sql);
    pst.setInt(1, fbid);
    ResultSet rs=pst.executeQuery();
    String author=rs.getString(1);
    rs.close();
    pst.close();
    conn.close();
    return author;
    }
    }index.jsp里面
    <s:iterator value="list"><s:property /></s:iterator>
    为什么就是迭代不出来呢?
      

  7.   


    你的这种方法遍历,输出的是list里对象的toString。
      

  8.   

    public String excute() throws SQLException
    {  
    list=IndexDAO.getFCname();
    fbnum=IndexDAO.getFBnumber(fbid);
    str=IndexDAO.getFBlast(fbid);
    fbtn=IndexDAO.getFBtoday(fbid);
    fbau=IndexDAO.getFBauthor(fbid);
    return SUCCESS;}你的方法名是excute~
    Struts里默认执行的方法名是execute,修改一下试试。
      

  9.   


    我什么都不说了,服了我自己的LC级错误!这是以前的第一个STRUTS2项目,一直找不到错在哪里!居然-_-值得好好检讨自己...谢谢啦
      

  10.   

    <default-action-ref name="index" />
    是一个BUG,无法连接数据库进行交换。
    在web.xml里面也是不能直接配置默认主页的,我是
    用了个goindex.jsp来进行客户端跳转进入index.jsp。好了,结贴!!!