• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logic:iterate

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
ViewProduct.jsp
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" 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"
"http://www.w3.org/TR/html4/loose.dtd">

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

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

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

</html:form>
<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:equal>

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

</tr>
</logic:iterate>
</table>
</logic:greaterThan>

</logic:present>

</body>
</html:html>

The ActionForm is ViewProductForm.java
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() {
super();
// TODO Auto-generated constructor stub
}
The ActionClass is ViewProductAction.java
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 {

Class.forName("com.mysql.jdbc.Driver");
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 + "' ");
//st.executeUpdate(Query);

ResultSet rs= st.executeQuery(Query);

while(rs.next()){
String pcode=rs.getString(1);
String Description=rs.getString(2);
results.add(pcode);
results.add(Description);
viewproductform.setResults(results);
}

}
conn.close();
//viewproductform.setResults(results);
System.out.println(results);

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

</action>
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(TagUtils.java:987)
PLEASE HELP

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Use a different name for each object of iteration.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can implement with c-tags

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

<c:forEach>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic