<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里面)
<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里面)
解决方案 »
- java 字符串问题是否能在简化
- Struts1.x中 struts-config.xml的forward的contextRelative的问题,非常迷惑,快崩溃了
- jboss4.2.1 下EJB例子
- 关于Lucene搜索结果的问题:IndexSearch与Hits
- 如何写用eclipse + tomcat5.0 连接SQL SERVER200的连接字符串呢?
- tomcat5.5.17,在Linux下启动没有控制台?
- Statement的一个很怪很怪的问题,请高手过来看看~
- struts2注解环境搭建
- 菜鸟问题:普通的servlet如何改成struts?
- 求助tomcat启动问题
- AnnotationConfiguration().buildSessionFactory()的一个问题
- 找错。。。。
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>
为什么就是迭代不出来呢?
你的这种方法遍历,输出的是list里对象的toString。
{
list=IndexDAO.getFCname();
fbnum=IndexDAO.getFBnumber(fbid);
str=IndexDAO.getFBlast(fbid);
fbtn=IndexDAO.getFBtoday(fbid);
fbau=IndexDAO.getFBauthor(fbid);
return SUCCESS;}你的方法名是excute~
Struts里默认执行的方法名是execute,修改一下试试。
我什么都不说了,服了我自己的LC级错误!这是以前的第一个STRUTS2项目,一直找不到错在哪里!居然-_-值得好好检讨自己...谢谢啦
是一个BUG,无法连接数据库进行交换。
在web.xml里面也是不能直接配置默认主页的,我是
用了个goindex.jsp来进行客户端跳转进入index.jsp。好了,结贴!!!