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>
怎么取不出数据??
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>
怎么取不出数据??
解决方案 »
- 新手书上范例问题 报错求助
- 求救!谁有jsp或Oracle的近三年的外文期刊啊!
- jsp页面中 需要在EL表达式后面使用substring方法 怎么做??
- 在一般的新闻发布系统中,如何吧jsp文件转化成shtml或是html文件?
- 调查:搞jsp开发工资有多少 来者有分
- 怎么利用jsp或servlet,把服务端上的某个word文档下载到客户端指定的目录中?
- Spring与activemq整合,消费者的消费速度非常慢
- 一个执行servlet的错误,请指教
- jsp中处理字符串的函数有那些,谢谢!
- 菜鸟的问题:如何用IE访问.jsp文件!!加急!
- Struts mapping转发的问题?
- 请问toncat启动出现这个错误怎么解决
去掉</logic:present> 行不行
2.flDao.insertFl(fll); 你确定添加数据成功了.
3.还有把你的
this.initConnection(); 也贴上来,好查错.
改成
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"> 试一下