写了这句话没有:<% page import="java.util.HashMap"%>

解决方案 »

  1.   

    写了啊.我弄不懂Hashmap在struts里到底可不可以用啊?
      

  2.   

    <%
         HashMap months = new HashMap();
         months.put("Jan","January");
         months.put("Feb","February");
         months.put("Mar","March");
         request.setAttribute("months",months);
    %>放到servlet里面试试呢
      

  3.   

    我现在发现了一个问题, 
    <bean:write name="element" property="key"/>
        
    <bean:write name="element" property="value"/><br>
    就是它出的问题,那个"key"和"value"是不是要在一个资源文件里定义啊?
      

  4.   

    提示说要有一个名字为element的javabean和property属性指定这个javabean的一个属性,这个属性为要遍历的hashmap,可是我不知道这个bean要怎么来写啊?大家指点指点吧!
      

  5.   

    property="这里面是对应着你的ACTIONFORM的BEAN值"另外最好给一个TYPE值,<logic:iterate id="element" indexId="ind" name="months" type="你的ACTIONFORM的全包类名">
      

  6.   

    我感觉我这个也没有用到formbean的内容啊,它也不需要提交和验证,这个hashmap的内容都在request中了,我直接显示就可以了.我不知道的是那个bean应该怎么来定义.
      

  7.   

    你的这段代码没有问题,将整个jsp页面贴出来。
      

  8.   


    <%@ page language="java" import="javax.servlet.http.Cookie,java.util.HashMap,java.util.Vector" pageEncoding="UTF-8"%><%@ 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" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
      <head>
        <html:base />
        
        <title>login.jsp</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
      </head>
      
      <body>
       <%
       Vector animals = new Vector();
       animals.addElement("dog");
       animals.addElement("cat");
       animals.addElement("bird");
       request.setAttribute("Animals",animals);
       %>
       
       <logic:iterate id="element" name="Animals" indexId="index">
       <bean:write name="index"/>..
       <bean:write name="element"/><br>
       </logic:iterate>
       <%
         HashMap h = new HashMap();
         String vegetables[]={"01","02"};
         String fruits[]={"03","04"};
         String flowers[]={"rose","baihe","kangnaixin"};
         h.put("vegetables",vegetables);
         h.put("fruits",fruits);
         h.put("flowers",flowers);
         request.setAttribute("catalog",h);
      %>
     <logic:iterate id="element" indexId="ind" name="catalog">
        <bean:write name="ind"/>
        <bean:write name="element" property="key"/>
        <logic:iterate id="elementValue" name="element" property="value" type="com.bean.element">
           ---<bean:write name="elementValue"/><br>
        </logic:iterate>  
        </logic:iterate><p>
        
    </body>
    </html:html>
      

  9.   

    你上面的这段代码有问题。我帮你改成你提问时的代码:
    <%@ page language="java" import="javax.servlet.http.Cookie,java.util.HashMap,java.util.Vector" pageEncoding="UTF-8"%><%@ 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" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
    <head>
    <html:base /><title>login.jsp</title><meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    </head><body>
    <%
    HashMap months = new HashMap();
    months.put("Jan","January");
    months.put("Feb","February");
    months.put("Mar","March");
    request.setAttribute("months",months);
    %>
    <logic:iterate id="element" indexId="ind" name="months">
    <bean:write name="ind"/>
    <bean:write name="element" property="key"/>
    <bean:write name="element" property="value"/><br/>
    </logic:iterate><p></body>
    </html:html>这段代码是每问题的,有问题的话,看看你的部属是否正确。
      

  10.   

    <bean:write name="element" property="key"/>
    <bean:write name="element" property="value"/>
    这两个标签的name和property系统会直接知道具体是哪个"value"和"key"么?我用在写个java bean来定义一下么?
      

  11.   

    你配了action吗?配了form吗?
    你的request.setAttribute("months",months);是往form里赋值吗?<logic:iterate id="element" indexId="ind" name="months">
    <bean:write name="ind"/>
    <bean:write name="element" property="key"/>
    <bean:write name="element" property="value"/><br/>
    </logic:iterate>
    这个只能从form里取值的。
      

  12.   

    没有,我的这段代码也是没有form和action,所以我就以为是不用那两个,直接就可以从页面了取出来的了呢.我有点不太懂,就是这个request不是在用户请求页面的时候她就起作用了么?   <%
       Vector animals = new Vector();
       animals.addElement("dog");
       animals.addElement("cat");
       animals.addElement("bird");
       request.setAttribute("Animals",animals);
       %>
       
       <logic:iterate id="element" name="Animals" indexId="index">
       <bean:write name="index"/>..
       <bean:write name="element"/><br>
       </logic:iterate>
       
      

  13.   

    <%
    HashMap months = new HashMap();
    months.put("Jan","January");
    months.put("Feb","February");
    months.put("Mar","March");
    request.setAttribute("months",months);
    %>
    <logic:iterate id="element" indexId="ind" name="months">
    <bean:write name="ind"/>
    <bean:write name="element" property="key"/>
    <bean:write name="element" property="value"/><br/>
    </logic:iterate><p>
    这段代码是不需要配置ation,formbean的。
    你肯定是项目结构有问题,或者struts包和tld没倒入项目中。不要再去找代码的问题了,自己好好看看项目结构。
      

  14.   

    这才是正确的<%
    strmemo_H = "memo(" + Integer.toString(i)+ ")";
    %>
    <td>
    <html:text name="eagle" property="<%=strmemo_H%>"value="<%=(String) mapModule.get("memo_" + Integer.toString(i))%>" >
    </td>在form中
    public static final String MEMO_KEY = "cmemo_";
    public String getMemo(String key) {
    if (tableMap.get(MEMO_KEY + key) == null) {
    return "";
    }
    return (String) tableMap.get(MEMO_KEY + key);
    } public void setMemo(String key, String value) {
    this.tableMap.put(MEMO_KEY + key, value);
    }