代码如下public class ListArticleAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response){
Connection conn = null;
try{
conn = getDataSource(request,"sqlServer").getConnection();
articleBean abean = new articleBean();
abean.setConn(conn);
List data = abean.ListArticle();
request.setAttribute("articleList",data);
return mapping.findForward("success");
}catch(SQLException e){
e.printStackTrace();
return mapping.findForward("failed");
}
}
}<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean"prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html"prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"prefix="logic" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<html:form method="post" action="/listarticle.do">
<div>
<table>
<tr><h2>文章预览</h2></tr>
<logic:present name="articleList">
<logic:iterate name="articleList" id="article">
<tr>
<td><html:link page="/article.do"><bean:write name="article" property="tilte"/></html:link></td>
<td><html:link page="/editarticle.do" paramId="article_id" paramName="article" paramProperty="article_id">编辑</html:link></td>
<td><html:link page="/delarticle.do" paramId="article_id" paramName="article" paramProperty="article_id">删除</html:link></td>
</tr>
<tr><bean:write name="article" property="truncate_note"/></tr>
<tr>
<td>作者:</td><td><bean:write name="article" property="autor"/></td>
<td> 分类:</td><td><bean:write name="article" property="article_class"/></td>
<td> 时间:</td><td><bean:write name="article" property="article_time"/></td>
</tr>
<hr/>
</logic:iterate>
</logic:present>
<logic:notPresent name="articleList">
<tr>未添文章!</tr>
</logic:notPresent>
</table>
<div>
<html:link page="/addarticle.jsp">增加文章</html:link>
</div>
</div>
</html:form>
</body>
</html>
数据库中已有数据,其它的配置都已完成,但页中查找不到数据库数据。
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response){
Connection conn = null;
try{
conn = getDataSource(request,"sqlServer").getConnection();
articleBean abean = new articleBean();
abean.setConn(conn);
List data = abean.ListArticle();
request.setAttribute("articleList",data);
return mapping.findForward("success");
}catch(SQLException e){
e.printStackTrace();
return mapping.findForward("failed");
}
}
}<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean"prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html"prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"prefix="logic" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<html:form method="post" action="/listarticle.do">
<div>
<table>
<tr><h2>文章预览</h2></tr>
<logic:present name="articleList">
<logic:iterate name="articleList" id="article">
<tr>
<td><html:link page="/article.do"><bean:write name="article" property="tilte"/></html:link></td>
<td><html:link page="/editarticle.do" paramId="article_id" paramName="article" paramProperty="article_id">编辑</html:link></td>
<td><html:link page="/delarticle.do" paramId="article_id" paramName="article" paramProperty="article_id">删除</html:link></td>
</tr>
<tr><bean:write name="article" property="truncate_note"/></tr>
<tr>
<td>作者:</td><td><bean:write name="article" property="autor"/></td>
<td> 分类:</td><td><bean:write name="article" property="article_class"/></td>
<td> 时间:</td><td><bean:write name="article" property="article_time"/></td>
</tr>
<hr/>
</logic:iterate>
</logic:present>
<logic:notPresent name="articleList">
<tr>未添文章!</tr>
</logic:notPresent>
</table>
<div>
<html:link page="/addarticle.jsp">增加文章</html:link>
</div>
</div>
</html:form>
</body>
</html>
数据库中已有数据,其它的配置都已完成,但页中查找不到数据库数据。
request.setAttribute("articleList",data);
date 初始化一下 就知道是不是 action传值的问题了。
估计是 data null 了。