Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

how to solve this problem???

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}

}
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javax.servlet.ServletException: BeanUtils.populate



Mostly this error occurs when form bean properties doesn't match with properties in Jsp
 
swenling wen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have solved this question
think you !!
of course this question is caused by what you have said.
 
Everybody's invited. Even this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic