Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Struts question

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on accessing the url ...http://localhost:9080/LearnStrutsWeb/getProduct.do , I am calling an Action class , which will in turn gets the info from a DB and populates it to a Value object (ProductTO) and in the ation iam redirecting the request to a JSP (displayAddProductForm.jsp).

The below is the code for the jsp.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:errors></html:errors>
<h3>Add a product</h3>
<html:form action="/saveProduct">
<table>
<tr>
<td>Product Name:</td>
<td><html:text property="productName"/></td>
</tr>
<tr>
<td>Description:</td>
<td><html:text property="description"/></td>
</tr>
<tr>
<td>Price:</td>
<td><html:text property="price"/></td>
</tr>
<tr>
<td><html:reset/></td>
<td><html:submit>UpdateProduct</html:submit></td>
</tr>
</table>
</html:form>

</body>
</html>


The action class code.
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Get the info from DB.
ProductTO prodto= new ProductTO();
prodto.setProductDecsription("XXXXXXXX");
prodto.setProductName("DPL");
prodto.setProductPrice("100000");

Form productForm11 = (Form)form;
productForm11.setProductName(prodto.getProductName());
productForm11.setDescription(prodto.getProductDecsription());
productForm11.setPrice(prodto.getProductPrice());

// Finish with
return mapping.findForward("success");


Struts file entry
<action path="/getProduct" type="app02a.action.GetProductAction" name="productForm" validate="false">
<forward name="success" path="/displayAddProductForm.jsp"></forward>
</action>

<form-bean name="productForm" type="app02a.form.Form"/>

question here is , when the action class executes the last line of code (mapping.findforward() ) , it redirect to teh JSP and the html fields , with in the JSP's are populated with the value , which i got from the DB. Can some one explain me , how are these fields getting populated.?

Thanks for your help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic