struts2的默认ACTION会执行execute()方法完成数据交互吗?还是只是个静态页面?

学无止境-逆流而上 2011-11-16 10:41:23
<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里面)
...全文
371 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
<default-action-ref name="index" />
是一个BUG,无法连接数据库进行交换。
在web.xml里面也是不能直接配置默认主页的,我是
用了个goindex.jsp来进行客户端跳转进入index.jsp。好了,结贴!!!
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 yanmushi 的回复:]
Java code

public String excute() throws SQLException
{
list=IndexDAO.getFCname();
fbnum=IndexDAO.getFBnumber(fbid);
str=IndexDAO.getFBlast(fbid);
fbtn=IndexDAO.getFBtoday(fbid);
fbau=IndexD……
[/Quote]

我什么都不说了,服了我自己的LC级错误!这是以前的第一个STRUTS2项目,一直找不到错在哪里!居然-_-值得好好检讨自己...谢谢啦
九两银 2011-11-16
  • 打赏
  • 举报
回复
跟踪调试一下,页面有没进入action先。如果没有就是路径有问题。
dreamboom 2011-11-16
  • 打赏
  • 举报
回复
看你页面有没有加载指定啊 再说你的method呢? 看看访问的是哪个方法啊
hellen_99010 2011-11-16
  • 打赏
  • 举报
回复
把你的Action execute() method贴出来看下。。。
fyswords 2011-11-16
  • 打赏
  • 举报
回复
没明白问题……要干什么在com.mobile_bbs.action.Doindex里写啊
艳沐石 2011-11-16
  • 打赏
  • 举报
回复
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,修改一下试试。
艳沐石 2011-11-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 itbasketplayer 的回复:]
<s:iterator value="list"><s:property /></s:iterator>
[/Quote]

你的这种方法遍历,输出的是list里对象的toString。
  • 打赏
  • 举报
回复
我的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>
为什么就是迭代不出来呢?
  • 打赏
  • 举报
回复
<default-action-ref name="index"></default-action-ref>好像是有BUG的吧,就是说它只能执行简单的视图而不能通过ACTION完成与数据库的交互。是吗?

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧