我想做一个目录,使用的是在网页的一部分使用一个action,让后返回的页面在该部分显示(该页面就是一个简单的列表页li)。但是列表却怎么样都没办法显示出来控制台中可以列出目录的列表项,可见service和dao没有问题。应该就是structs标签写错的原因。可是我试了别的比如说#catalog.getCatalogname()的形式但是都不行。麻烦各位看看!本来突然发现忘记加taglib声明,但是加了也是没用。试了随便打一个数在menu,在catalogPage.jsp是可以显示的。我的DishAction.java
package org.action;import java.util.Iterator;
import java.util.List;
import java.util.Map;import org.model.Catalog;
import org.model.Dish;
import org.service.ICatalogService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class DishAction extends ActionSupport
{
protected ICatalogService catalogService;
public void setCatalogService(ICatalogService catalogService)
{
this.catalogService = catalogService;
}
public String browseCatalog() throws Exception
{
List catalogs=catalogService.getAllCatalogs();
Map request=(Map)ActionContext.getContext().get("request");
request.put("catalogs", catalogs);
//在控制台列出所有的项
Iterator<Catalog> iterator=catalogs.iterator();
while(iterator.hasNext())
{
Catalog C=iterator.next();
System.out.println(C.getCatalogid()+C.getCatalogname());
}
return SUCCESS;
}}每次刷新jsp的时候都是有结果的
catalogPage.jsp(主界面 部分代码)
有加声明<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %><nav class="left-sb-menu">
<div class="left-sb-menu-title"><strong>菜品分类</strong></div>
<s:action name="browseCatalog" executeResult="true"></s:action><
/nav>
menu.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>menu</title>
<link rel="stylesheet" href="css/style.css" media="screen">
<link rel="stylesheet" href="css/home-page.css" media="screen">
<link rel="stylesheet" href="css/ribbon-guideline.css" media="screen">
<link rel="stylesheet" href="css/Catalog-products.page.css" media="screen">
</head>
<body class="no-js front-page">
<ul>
<s:iterator value="#request.['catalogs']" id="catalog">
<li>
<s:property value="#catalog.getCatalogname()" />
</li>
</s:iterator>
</ul>
</body>
</html>
Iteratorstructs2标记
package org.action;import java.util.Iterator;
import java.util.List;
import java.util.Map;import org.model.Catalog;
import org.model.Dish;
import org.service.ICatalogService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class DishAction extends ActionSupport
{
protected ICatalogService catalogService;
public void setCatalogService(ICatalogService catalogService)
{
this.catalogService = catalogService;
}
public String browseCatalog() throws Exception
{
List catalogs=catalogService.getAllCatalogs();
Map request=(Map)ActionContext.getContext().get("request");
request.put("catalogs", catalogs);
//在控制台列出所有的项
Iterator<Catalog> iterator=catalogs.iterator();
while(iterator.hasNext())
{
Catalog C=iterator.next();
System.out.println(C.getCatalogid()+C.getCatalogname());
}
return SUCCESS;
}}每次刷新jsp的时候都是有结果的
catalogPage.jsp(主界面 部分代码)
有加声明<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %><nav class="left-sb-menu">
<div class="left-sb-menu-title"><strong>菜品分类</strong></div>
<s:action name="browseCatalog" executeResult="true"></s:action><
/nav>
menu.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>menu</title>
<link rel="stylesheet" href="css/style.css" media="screen">
<link rel="stylesheet" href="css/home-page.css" media="screen">
<link rel="stylesheet" href="css/ribbon-guideline.css" media="screen">
<link rel="stylesheet" href="css/Catalog-products.page.css" media="screen">
</head>
<body class="no-js front-page">
<ul>
<s:iterator value="#request.['catalogs']" id="catalog">
<li>
<s:property value="#catalog.getCatalogname()" />
</li>
</s:iterator>
</ul>
</body>
</html>
Iteratorstructs2标记
<li>
<s:property value="#catalog.getCatalogname()" />
</li>
</s:iterator>
还是不行啊,你可以帮我改成jsp的java代码片段吗?这个我都不会可是又很急。先谢谢了。好人一生平安
这样试试:<s:iterator value="#request.catalogs">
<li>
<s:property value="#catalogname" />
</li>
</s:iterator>
不晓得Catalog是不是有catlogname属性以及其get方法?