File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts question" Watch "Struts question" New topic
Author

Struts question

Prannav Santhosh
Greenhorn

Joined: May 09, 2009
Posts: 29
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts question