This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Logic:iterate" Watch "Logic:iterate" New topic


Md Asif S Sayeed

Joined: Oct 20, 2009
Posts: 2
Hi all,
I am new to struts i am doing a simple project but i m stuck.please help
I have got a product table in the database.I am trying to retrieve the value about a particular productid from the database.I am giving a Product id in a jsp page and i need to retrieve the values in the same page.I am using logic:iterate for the same but i m unable to please help.
the pages are...
<%@ taglib uri="" prefix="bean" %>
<%@ taglib uri="" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View Page Of Product</title>

<h3>This is a view page of product.</h3>
<html:form action="/ViewProduct">

<td align="right">Product Code:</td>
<td><html:text property="pcode" value=""/></td>
<td><html:submit value="view"/></td>
<td><html:link forward="ProductDelete"><html:button value="Delete" property=""/></html:link>

<logic:present name="ViewProductForm" property="results">

<hr width="100%" size="1" noshade="true">

<bean:size id="size" name="ViewProductForm" property="results"/>
<logic:equal name="size" value="0">
<center><font color="red"><b>No Product Found</b></font></center>

<logic:greaterThan name="size" value="0">
<table border=1>
<th>Product Code</th>
<logic:iterate id="results" name="ViewProductForm" property="results">
<td><bean:write name="results" property="pcode"/></td>
<td><bean:write name="results" property="Description"/></td>




The ActionForm is
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class ViewProductForm extends ActionForm {

private String pcode=null;
private String Description=null;

public String getDescription() {
return Description;

public void setDescription(String Description) {
this.Description = Description;
private List results = null;

public String getPcode() {
return pcode;

public void setPcode(String pcode) {
this.pcode = pcode;

public void setResults(List results) {
this.results = results;
public List getResults() {
return results;

public ViewProductForm() {
// TODO Auto-generated constructor stub
The ActionClass is
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.*;
import java.util.ArrayList;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class ViewProductAction extends Action {

Connection conn=null;
Statement st;
String userName="root";
String Password="root";
String url="jdbc:mysql://localhost/surevac";
String username;
String password;
ArrayList results=new ArrayList();

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

conn=DriverManager.getConnection(url, userName, Password);
ViewProductForm viewproductform=( ViewProductForm) form;
String pcode1=viewproductform.getPcode();
if (pcode1 != null && pcode1.trim().length() > 0){
st = conn.createStatement();
String Query = ("SELECT Pcode,Description from productlist where pcode='" + pcode1 + "' ");

ResultSet rs= st.executeQuery(Query);

String pcode=rs.getString(1);
String Description=rs.getString(2);


return mapping.getInputForward();

The Relative mappin in Struts-config.xml are
<form-bean name="ViewProductForm" type="ViewProductForm"/>
<action name="ViewProductForm" path="/ViewProduct" type="ViewProductAction" input="/ViewProduct.jsp" scope="request" validate="true">

But I am getting this error
ApplicationDispatcher[/SurevacManagement] PWC1231: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: No getter method for property: "pcode" of bean: "results"
at org.apache.struts.taglib.TagUtils.lookup(

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.

[Asking smart questions] [About Bear] [Books by Bear]
David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Use a different name for each object of iteration.
srikanth nallapaneni

Joined: Jun 08, 2009
Posts: 4
You can implement with c-tags

<c:forEach var="result" items="${records}">

Consider Paul's rocket mass heater.
subject: Logic:iterate
It's not a secret anymore!