【问题标题】:How to use <div> properly in Struts 2如何在 Struts 2 中正确使用 <div>
【发布时间】:2021-05-10 03:54:45
【问题描述】:

我在 JSP 页面中有一个由 Struts 标记迭代的列表,当我尝试为每次迭代创建 &lt;div&gt; 时,它无法正常工作。

这是我的代码:

<div style="height:300px;width:700px;border:solid 2px white;overflow:scroll;overflow-x:hidden;overflow-y:scroll;">

        <s:if test="#request.questions !=null && #request.questions.size()>0">
          <s:set var="id"  value="-1" />
               
           <s:iterator value="#request.questions" status="index" var="ques">
                
             <s:if test="%{#id != surveyId}"> 
               name <s:property value="surveyId"/>
                <s:set var="id"  value="surveyId"/>
                </s:if>
              
              <s:div "  id="questionNumber<s:property value='sortOrder'/>">
                    <span class="questionCode"><s:property value="questioncode"/>. </span> 
                     
                    <span class="questionText"><s:property value="questionname"/> </span>
                
                    <s:div class="answersBlock">
                        <s:div><label class="answerLabel">Ans. <s:property value="answername"/> </label></s:div>
                    </s:div>
                
                </s:div>
                
                </s:iterator>
        </s:if>
        <s:else>
            No Survey Taken Yet.
        </s:else></p>
</div>

在这里我得到如下格式的日期

id 281
q1: question
ans: -----

id: 282
q1:question
ans: ---
q2: question
ans:----
q3:question
and:----

现在我想要在这里为ids 281、282 创建两个单独的&lt;div&gt;,并将每个id 的内容放在不同的&lt;div&gt; 中。

我正在动态获取数据,所以它可能超过 2 个id,因此在它们的基础上创建一个&lt;div&gt;,一个id 可以有多个问题的答案。

【问题讨论】:

  • 只使用普通的 div-s。
  • Struts div 是基于 Ajax 的,推荐使用 jQuery 插件
  • &lt;s:div " id="questionNumber&lt;s:property value='sortOrder'/&gt;"&gt; 在很多方面都是无意义的,最关键的是你不能像这样嵌套 JSP 标签。
  • &lt;s:div&gt; 不是基于 ajax 的。

标签: java html arraylist struts2


【解决方案1】:

您尝试使用 s:div 标签,如 html div,但这是错误的标签用法。 s:div 是一个 Ajax 标记,用于通过 Ajax 调用加载 html 内容。但你不需要它,只需使用 HTML div

另外请注意,如果您使用的是 Struts 标签,请确保不要将它们嵌套在 Struts 标签的头部或属性中。您只能将标签嵌套在 Struts 标签的主体中。

<div id="questionNumber<s:property value='sortOrder'/>">
    <span class="questionCode"><s:property value="questioncode"/>. </span> 

    <span class="questionText"><s:property value="questionname"/> </span>

    <div class="answersBlock">
        <div><label class="answerLabel">Ans. <s:property value="answername"/> </label></div>
    </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多