简体   繁体   English

struts2的Javascript代码

[英]Javascript code to struts2

how to write the below code using struts2 tag library. 如何使用struts2标记库编写以下代码。 since struts2 have many tags like iterator, if etc. but how the below code can be achieved using that? 因为struts2有许多标签,如迭代器,如果等,但是如何使用它来实现下面的代码呢?

how we can initialize variable in struts2 tag and after that how to apply increment or decrements operation like the code shown below? 我们如何在struts2标签中初始化变量,然后如何应用增量或减量操作,如下所示的代码?

int j=-1;
for(int i=0;i<4;i++)
{
j++;
if(j==0)
{
}
if(j==1)
{
}
if(j==2)
{
j=-1;
}
}

This is my jsp page where i used the java code within the scriplet tags 这是我的jsp页面,我在scriplet标签中使用了java代码

<h3>Our Latest Projects</h3>
<%! int j = -1; %>

<%
  for (int i = 0; i < 4; i++) {
    j++;
%>
  <% if (j == 0) { %>
<div class="wrapper">
  <article class="grid_4 alpha">
    <h4 class="p2">Project 1</h4>
    <figure><a href="#"><img class="img-border" src="images/page4-img1.jpg" alt=""/></a></figure>
    <div class="box" style="height: 20px; width: 257px;">
      <div class="padding">
        <a href="#">View Details</a>
      </div>
    </div>
  </article>
  <% } %>

  <% if (j == 1) { %>
  <article class="grid_4">
    <div class="indent-left4">
      <h4 class="p2">Project 2</h4>
      <figure><a href="#"><img class="img-border" src="images/page4-img2.jpg" alt=""/></a></figure>
      <div class="box" style="height: 20px; width: 257px;">
        <div class="padding">
          <a href="#">View Details</a>
        </div>
      </div>
    </div>
  </article>
  <% } %>
  <% if (j == 2) { %>
  <article class="grid_4 omega">
    <div class="indent-left3">
      <h4 class="p2">Project 3</h4>
      <figure><a href="#"><img class="img-border" src="images/page4-img3.jpg" alt=""/></a></figure>
      <div class="box" style="height: 20px; width: 257px;">
        <div class="padding">
          <a href="#">View Details</a>
        </div>
      </div>
    </div>
  </article>
</div>
<br><br>
<% j = -1; %>
<% } %>
<% } %>

What a disaster. 这悲剧。

Here's everything except for the article > div styling since it wasn't clear how it was related to anything else; 这是除了article > div样式之外的所有内容,因为它不清楚它是如何与其他任何东西相关的; you should be able to figure it out based on the rest of this code. 你应该能够根据这段代码的其余部分弄清楚它。

<div class="wrapper">
  <s:iterator begin="1" end="#session.count" status="stat">
    <s:set var="artClass" value="#stat.first ? 'alpha' : #stat.last ? 'omega' : ''" />

    <article class="grid_4 <s:property value="#artClass"/>">
      <div> <!-- Not really sure what you want here for the class. -->
        <h4 class="p2">Project <s:property value="#stat.count"/></h4>
        <figure><a href="#"><img class="img-border" src="images/page4-img<s:property value="#stat.count"/>.jpg" alt=""/></a></figure>
        <div class="box" style="height: 20px; width: 257px;">
          <div class="padding">
            <a href="#">View Details</a>
          </div>
        </div>
      </div>
    </article>
  </s:iterator>
</div>

Also, if "alpha" and "omega" are for the first and last columns, and not the first/last items in the list, you'd want to change this up somewhat. 此外,如果“alpha”和“omega”用于第一列和最后一列,而不是列表中的第一个/最后一个项,则需要稍微更改一下。 Personally, I would split the list up into a list of threes in the Java code and do a double-iteration: 就个人而言,我会将列表拆分为Java代码中的三个列表并进行双重迭代:

<s:iterator value="listOfLists" var="list">
  <s:iterator value="list" status="stat">
    <s:set var="artClass" value="#stat.first ? 'alpha' : #stat.last ? 'omega' : ''" />

    <article class="grid_4 <s:property value="#artClass"/>">
      <div> <!-- Not really sure what you want here for the class. -->
        <h4 class="p2">Project <s:property value="#stat.count"/></h4>
        <figure><a href="#"><img class="img-border" src="images/page4-img<s:property value="#stat.count"/>.jpg" alt=""/></a></figure>
        <div class="box" style="height: 20px; width: 257px;">
          <div class="padding">
            <a href="#">View Details</a>
          </div>
        </div>
      </div>
    </article>
  </s:iterator>
  <br/><br/> <!-- Use CSS. -->
</s:iterator>

You could also encapsulate this in a custom tag and utility method and make things very clean. 您还可以将其封装在自定义标记和实用程序方法中,并使事情变得非常干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM