Topic: 求助:Struts问题

  Print this page

1.求助:Struts问题 Copy to clipboard
Posted by: guomi2004
Posted on: 2008-03-19 20:10

修改数量
页面:

<form action="/commerce/cart.do?method=update" method="get">
  <table>
    <tr>
     <td>数量</td>    
    </tr>
    
<logic:iterate id="cartItem" scope="session" name="Sessio nContainer" property="cart.items">
<tr>
<td><input type="text" name="qty_<bean:write name="cartItem" property="id"/>" value="<bean:write name="cartItem" property="quantity"/>">
</td>
</tr>
</logic:iterate>
<tr>
<td colspan="1" align="center">
<html:submit></html:submit>
</td>
</tr>
</table>
</form>

action:

public class GetItemDetailActions extends CommerceDispatchAction {
public ActionForward update(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
    // TODO Auto-generated method stub
    updateQuantity(request);
    return mapping.findForward("success");
  }
  
  private void updateQuantity(HttpServletRequest request){
    SessionContainer sessionContainer=this.getSessionContainer(request);
    Enumeration enum1=request.getParameterNames();
    while(enum1.hasMoreElements()){
      String ids=(String)enum1.nextElement();      
      if(ids.startsWith("qty_")){
        String qtyString =request.getParameter(ids.substring(4,ids.length()));        
        sessionContainer.getCart().updateQuantity(Integer.parseInt(ids), Integer.parseInt(qtyString));  
      }
    }
  }
}

struts-config。xml

<action
  path="/cart"
   scope="request"
   type="commerce.action.GetItemDetailActions"
   validate="false"
   parameter="method" >
    <forward name="success" path="/commerce/cart.jsp"></forward>
</action>

异常:
javax.servlet.ServletException: Request[/cart] does not contain handler parameter named 'method'. This may be caused by whitespace in the label text.
  org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:222)
  org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:256)
  org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
  org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
  org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
  org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
  org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

2.Re:求助:Struts问题 [Re: guomi2004] Copy to clipboard
Posted by: hy806806
Posted on: 2008-07-28 16:31

does not contain handler parameter named 'method'. This may be caused by whitespace in the label text

////////////////
你/card.do?后面为什么要加method=update? 难道你想传参数??呵呵

3.Re:求助:Struts问题 [Re: guomi2004] Copy to clipboard
Posted by: andy_wang_5
Posted on: 2008-07-30 09:32

commerce/cart.do?method=update 是可以的.不过要从DispatchAction继承.

4.Re:求助:Struts问题 [Re: guomi2004] Copy to clipboard
Posted by: tiger_hlq
Posted on: 2008-09-12 10:46

'method'这个参数传递可以在action中传递, 或是在struts-config.xml中传递.
在JSP中是不对的

5.Re:求助:Struts问题 [Re: guomi2004] Copy to clipboard
Posted by: nihaolaogao
Posted on: 2008-11-21 23:54

在Form后的action中是不能加参数的.
你可写一个超连接,或写一个js.应该可以传过去了.比如
document.getDocumentById("Form").action="/commerce/cart.do?method=update";
document.getDocumentById("Form").submit();


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923