dao: 
public  ArrayList getAllFl(){     String sql = "SELECT FL FROM FL"; 
    ArrayList fls = new ArrayList(); 
    
try{ 
this.initConnection(); 
ResultSet rs = conn.createStatement().executeQuery(sql); 
while(rs.next()){ 
Fl fl = new Fl(); 
fl.setFl(rs.getString("FL")); 
    fls.add(fl);  
              } 
}catch(Exception ex){} 
finally{ 
try{ 
this.closeConnection(); 
}catch(Exception ex){} 
} return fls; } 
action: 
package com.yourcompany.struts.action; 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 com.yourcompany.struts.form.FirstForm; 
import dao.FlDao; 
import java.util.ArrayList; 
import vo.Fl; 
public class FirstAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response)throws Exception { 
FirstForm firstForm = (FirstForm) form;// TODO Auto-generated method stub 
String fl=firstForm.getFl(); 
fl = new String(fl.getBytes("ISO-8859-1")); 
FlDao flDao=new FlDao(); 
Fl fll=new Fl(); 
fll.setFl(fl); 
flDao.insertFl(fll); 
ArrayList fls=flDao.getAllFl(); 
request.setAttribute("fls",fls); 
return new ActionForward("/first.jsp"); 
  } 

first.jsp 
<%@ page language="java" pageEncoding="gb2312"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> 
<html> 
<head> 
<title>JSP for FirstForm form </title> 
</head> 
<body> 
<html:form action="/first"> 
添加分类: <html:text property="fl"/> 
<html:submit/> 
</html:form> 
    <logic:present name="FirstForm" property="fls" scope="request"> 
    <logic:iterate id="fl" name="fls" scope="request"> 
<tr> 
<td> <bean:write name="fl" property="fl"/> </td> 
</tr> 
</logic:iterate> 
</logic:present> 
</body> 
</html> 
怎么取不出数据??

解决方案 »

  1.   

    <logic:iterate id="fl" name="FirstForm" property="fls" scope="request"> 
      

  2.   

    有了<logic:iterate id="fl" name="FirstForm" property="fls" scope="request"> 
    去掉</logic:present> 行不行
      

  3.   

    噢,我找你的改的应该这样<logic:present name="fls" scope="request"> <logic:iterate id="fl" name="fls" scope="request"> fls才是你传过来的
      

  4.   

    哦,与中文无关,你在action中吧fls输出来看看是不是空
      

  5.   

    1.先看 传过来的 fl有值没有.
    2.flDao.insertFl(fll);  你确定添加数据成功了.
    3.还有把你的
    this.initConnection(); 也贴上来,好查错.
      

  6.   

    楼主怎么又开了个帖子request.setAttribute("fls",fls); 
    改成
    request.getSession().setAttribute("fls",fls); <logic:present name="FirstForm" property="fls" scope="request"> 
    <logic:iterate id="fl" name="fls" scope="request"> 
    改成
    <logic:present name="FirstForm" property="fls" scope="session"> 
    <logic:iterate id="fl" name="fls" scope="session"> 试一下