aspose file tools*
The moose likes Struts and the fly likes how to solve this problem??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to solve this problem???" Watch "how to solve this problem???" New topic
Author

how to solve this problem???

swenling wen
Ranch Hand

Joined: Jun 07, 2006
Posts: 32
when I run program, these question below happend:
who can help me??? thanks your reading!!
exception

javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107)


root cause

java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107)

form:
<html:form action="/shop/cart.do" method="post">
<font size="2">num:</font><input name="qty" type="text" size="2"><br>
<input type="hidden" name="productId" value="<bean:write name="products" property="productId"/>"><input type="hidden" name="action" value="addcart">
<input type="hidden" name="price" value="<bean:write name="products" property="discount"/>">
<input type="hidden" name="productName" value="<bean:write name="products" property="productName"/>">
<input type="submit" name="B1" value="add products">
</html:form>
action:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl

package com.sinosystem.shop.web.action;

import com.sinosystem.shop.web.form.ItemForm;
import com.sinosystem.shop.domain.Cart;
import com.sinosystem.shop.domain.Item;

import javax.servlet.http.*;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
* MyEclipse Struts
* Creation date: 06-08-2006
*
* XDoclet definition:
* @struts.action path="/addcart" name="itemForm" scope="request" validate="true"
*/
public class CartAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
System.out.print("action!!");
ItemForm itemForm = (ItemForm) form;
HttpSession session=request.getSession();
Cart cart = (Cart)session.getAttribute("cart");
if (cart==null) {
cart = new Cart();
cart.getItemList().add(itemForm.getItem());
}
else {
boolean finditem = false;
for(int i=0; i<cart.getItemList().size(); i++) {
Item item = (Item)cart.getItemList().get(i);
if (item.getProductId() == itemForm.getProductId()) {
item.setQty(item.getQty() + itemForm.getQty());
finditem = true;
break;
}
}
if (!finditem) {
cart.getItemList().add(itemForm.getItem());
}
}
cart.setCount(cart.getCount() + itemForm.getQty());
cart.setTotal(cart.getTotal() + itemForm.getQty()*itemForm.getPrice());
session.setAttribute("cart", cart);
return mapping.findForward("addcart");
}

}

ItemForm:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl

package com.sinosystem.shop.web.form;

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.DynaActionForm;

import com.sinosystem.shop.domain.Item;

/**
* MyEclipse Struts
* Creation date: 06-08-2006
*
* XDoclet definition:
* @struts.form name="ItemForm"
*/
public class ItemForm extends ActionForm {

/**
*
*/
private static final long serialVersionUID = -3078451387943993516L;
// --------------------------------------------------------- Instance Variables

/**
*
*/

/** item property */
private Item item;

// --------------------------------------------------------- Methods

/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {

// TODO Auto-generated method stub
return null;
}

/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {

// TODO Auto-generated method stub
}

/**
* Returns the item.
* @return Item
*/
public Item getItem() {
return item;
}

/**
* Set the item.
* @param item The item to set
*/
public void setItem(Item item) {
this.item = item;
}

public void setPrice(String price) {
this.item.setPrice(Integer.parseInt(price));
}

public void setProductId(String productId) {
this.item.setProductId(Integer.parseInt(productId));
}

public void setProductName(String productName) {
this.item.setProductName(productName);
}

public void setQty(String qty) {
this.item.setQty(Integer.parseInt(qty));
}

public int getPrice() {
return this.item.getPrice();
}

public int getProductId() {
return this.item.getProductId();
}

public String getProductName() {
return this.item.getProductName();
}

public int getQty() {
return this.item.getQty();
}

}
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
javax.servlet.ServletException: BeanUtils.populate


Mostly this error occurs when form bean properties doesn't match with properties in Jsp
swenling wen
Ranch Hand

Joined: Jun 07, 2006
Posts: 32
I have solved this question
think you !!
of course this question is caused by what you have said.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to solve this problem???