id是自己定义的,在循环里面要用到,name是对象集合中的一个对象,循环里面要显示这个对象的属性,property是用于对象里面的潜套,如果没有这样的就可以不用写。
解决方案 »
- 关于将xml文件生成jar包的问题
- MyEclipse的UML工具的字体调整在哪啊?
- 代码的编写
- 生成GAR文件时遇到的问题,请指教
- 一个JSP错误The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
- 想请教学习Java的方法,可以指导一下吗?谢谢!
- j2ee不能启动
- dongdongshu接分!
- 问一个简单的问题:EJBHome和EJBLocalHome有什么区别?
- XML的输出:我已经建好一个完整的Document对象,如何把它输出成String呢?
- struts的标签问题?
- java初级问题
<bean:write name="employee" property="name">
</logic:iterate>
取得的是department集合中一个对象中的name属性值。
<logic:iterate id="employee" name="department">
<tr>
<td width="11%"><bean:write name="employee" property="sex"/> </td>
<td width="11%"><bean:write name="employee" property="name"/> </td>
<td width="11%"><bean:write name="employee" property="age"/> </td>
</tr>
struts-config.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="workActionForm" type="src.workActionForm" />
</form-beans>
<action-mappings>
<action name="workActionForm" path="/workAction" scope="request" type="src.workAction" validate="true" redirect="false">
<forward name="success" path="/work.jsp" />
</action>
</action-mappings>
</struts-config>workAction.java内容:
package src;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class workAction extends Action {
public ActionForward
execute(ActionMapping mapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse res){
workActionForm myform=(workActionForm)form;
String[][] temp = {{"a1","a2","a3"},{"b1","b2","b3"}};
myform.setabc(temp);
return(mapping.findForward("success"));}
}workActionForm.java内容:
package src;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
public class workActionForm extends ActionForm {
private String[][] abc = null;
public void setabc(String[][] abc) {
this.abc = abc;
}
public String[][] getabc() {
return this.abc;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
}
}work.jsp内容:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="WEB-INF/struts-tiles.tld" prefix="tiles" %>
<html:html>
<head>
<title>
work
</title>
</head>
<body bgcolor="#ffffff">
<h1>
welcome to my test !!
</h1>
</body>
</html:html>
<html:form action="workAction.do" >
<logic:iterate id="workActionForm" name="workActionForm" property="abc" offset="0" >
<% String[] temp = (String[]) workActionForm; %>
<%=temp[0]%> | <%=temp[1]%> | <%=temp[2]%> <p>
</logic:iterate>
</html:form>
<tr align="center">
<td width="16%">桌位号</td>
<td width="19%">标准人数</td>
<td width="22%">类型</td>
<td width="43%">操作</td>
</tr>
<logic:present name="tables"> //如果存在名为"tables"的属性(实际上是一个ArrayList)
<logic:iterate id="table" name="tables"> //循环该属性变量,将其中对象元素取出来,命名为"table"
<tr>
<td><bean:write name="table" property="tableID"/></td> //显示"table"对象的属性
<td><bean:write name="table" property="seats"/></td>
<td><bean:write name="table" property="type"/></td>
<td><html:link page="/TableUsing.do" paramId="tableID" paramName="table" paramProperty="tableID">安排</html:link>
<html:link page="/TableBook.do" paramId="tableID" paramName="table" paramProperty="tableID">预订</html:link>
</td>
</tr>
</logic:iterate>
</logic:present>
</table>上面是我在做东东时的部分代码,希望对你有帮助。其中的注释是现加上的,方便看懂。
说明:“tables”是一个ArrayList类型的属性,在某个action中有:……
TableBean tableBean=new TableBean();
ArrayList tables=(ArrayList)tableBean.tableQuery(seats,tableType,ifSmoke);
request.setAttribute("tables",tables); //设置名为"tables"的属性,在jsp文件中取出来
return(mapping.findForward("tablelist"));名为"tablelist"的Forward指向最开始代码所在的jsp文件。
你的例子运行不通,具体问题实在是一言难尽。
建议你还是找本书仔细看看,有个整体的概念。在csdn上只能是某个具体的问题不明白,问一下,得不到一个整体的概念的。