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