Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:27:29+00:00 2026-06-10T07:27:29+00:00

how to write the below code using struts2 tag library. since struts2 have many

  • 0

how to write the below code using struts2 tag library. since struts2 have many tags like iterator, if etc. but how the below code can be achieved using that?

how we can initialize variable in struts2 tag and after that how to apply increment or decrements operation like the code shown below?

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

<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; %>
<% } %>
<% } %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:27:31+00:00Added an answer on June 10, 2026 at 7:27 am

    What a disaster.

    Here’s everything except for the article > div styling since it wasn’t clear how it was related to anything else; 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. Personally, I would split the list up into a list of threes in the Java code and do a double-iteration:

    <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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote below code to compare to arrays that have same elements but in
Anybody knows how to write the piece of code below using generics AND avoiding
I have this below code(this is a sample, there are many more other conditions
I am using this below code to re-write URL : RewriteEngine on RewriteRule ^buynow/(.*)$
I am using the below code for saving an image to SD Card. But
The below code is works using document.write . How to display the value exceeded
Using the Exiv2 library to write some exif tags to an image i'm running
When I write the below code, why do I get avaliable Thread number like
I was uploading my file using below code,it works fine but some time it
i write below code for sending id to another php file function selectCheckBox(k) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.