index.jsp <form action="workflow.do" method="post"
enctype="multipart/form-data">
<input type="hidden" name="method" value="add">
<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0"
style="width: 580px;">
<TBODY>
<TR>
<!-- 这里是添加、编辑界面的标题 -->
<td align="center" class="tdEditTitle">
添加或更新流程信息
</TD>
</TR>
<TR>
<td>
<!-- 主输入域开始 -->
请选择上传的流程文件:
<input type="file" name="processDefinition" />
<br>
请选择上传的流程图片:
<input type="file" name="processImage" />
<br>
<input type="submit" name="submit" value="上传" /> <!-- 主输入域结束 -->
</td>
</TR>
</TBODY>
</TABLE>
</form>WorkflowAction.java public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.err.println("hello");
WorkflowActionForm waf = (WorkflowActionForm) form;
workflowManager.deployProcessDefinition(waf.getProcessDefinition()
.getFileData(), waf.getProcessImage().getFileData());
return mapping.findForward("add_success");
}为什么WorkflowAction.java中的add方法不被执行?其他方法可以执行。

解决方案 »

  1.   

    1.可不可以帖一下相关struts的配置文件部分
    2.我学艺不精,提出我的看法,楼上楼下勿喷
    3.看你的action类应该使用的是struts1吧,记得struts1的action里面只能使用execute方法吧,
    如果要使用自定义的方法可以这样:actionForward = this.add(mapping, form,
    request, response);
    4.欢迎交流,共同学习
      

  2.   

    struts配置文件如下: <action name="workflowActionForm" path="/workflow" scope="request"
    parameter="method" type="org.springframework.web.struts.DelegatingActionProxy">
    <forward name="index" path="/workflow/index1.jsp"></forward>
    <forward name="add_success" path="workflow.do" redirect="true"></forward>
    </action>
      

  3.   

    没看到 struts 有调用add方法呀?
      

  4.   


    <form action="workflow.do" method="post"
        enctype="multipart/form-data">
        <input type="hidden" name="method" value="add">隐藏域中设置了method,它不应该是执行add方法吗?
      

  5.   

    去掉隐藏域,这样workflow.do?method=add这样提交下看看,
      

  6.   

    1.如果你这么调用的话 
    workflow.do?method=add
    2.后台就需要这么得到public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
    String action = request.getParament("method");
    if(action.equals("add")){
    actionForward = this.add(mapping, form,
                            request, response);
    }
    }
    public ActionForward add(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.err.println("hello");
        WorkflowActionForm waf = (WorkflowActionForm) form;
        workflowManager.deployProcessDefinition(waf.getProcessDefinition()
                .getFileData(), waf.getProcessImage().getFileData());
        return mapping.findForward("add_success");
    }
      

  7.   


    <form action="workflow.do" method="post"
    enctype="multipart/form-data">
    <input type="hidden" name="method" value="add">
    <TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0"
    style="width: 580px;">
    <TBODY>
    <TR>
    <!-- 这里是添加、编辑界面的标题 -->
    <td align="center" class="tdEditTitle">
    添加或更新流程信息
    </TD>
    </TR>
    <TR>
    <td>
    <!-- 主输入域开始 -->
    请选择上传的流程文件:
    <input type="file" name="processDefinition" />
    <br>
    请选择上传的流程图片:
    <input type="file" name="processImage" />

    <br>
    <input type="submit" name="submit" value="上传" /> <!-- 主输入域结束 -->
    </td>
    </TR>
    </TBODY>
    </TABLE>
    </form>把
    enctype="multipart/form-data"

    请选择上传的流程文件:<input type="file" name="processDefinition" />
    <br>
    请选择上传的流程图片:<input type="file" name="processImage" />

    去掉就可以执行add方法了。为什么???
      

  8.   


    因为你让表单提交是按二进制流来提交的、楼主可以查查资料表单的enctype有三种方式来交互enctype="multipart/form-data"如果你表单若要带这个参数 且还要带自己设定的参数的话  是需要分离出来的、不过struts1没用过、自己动手搜索下struts1上传文件并传递参数如何做吧、
      

  9.   

    页面中的action的url和action类中的方法名不一样啊   你修改成一样的试试
      

  10.   

    Actionpublic class UserAction extends DispatchAction {


    /**
     * 测试
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     */
    public ActionForward add(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    System.out.println("增加");

    return mapping.findForward("success");
    }}
    Formpublic class UserForm {
    private String fileName;
    private File processDefinition;
    private File processImage; public String getFileName() {
    return fileName;
    } public void setFileName(String fileName) {
    this.fileName = fileName;
    } public File getProcessDefinition() {
    return processDefinition;
    } public void setProcessDefinition(File processDefinition) {
    this.processDefinition = processDefinition;
    } public File getProcessImage() {
    return processImage;
    } public void setProcessImage(File processImage) {
    this.processImage = processImage;
    }}
    web.xml <!-- Action Servlet Configuration --> <servlet>    <servlet-name>action</servlet-name>    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>    <init-param>      <param-name>config</param-name>      <param-value>/WEB-INF/struts-config.xml</param-value>    </init-param>    <load-on-startup>1</load-on-startup> </servlet> <!-- Action Servlet Mapping --> <servlet-mapping>    <servlet-name>action</servlet-name>    <url-pattern>*.do</url-pattern> </servlet-mapping>
    struts-config.xml
    顺便说句,上面有的说?method=add访问不到,这里说明下
    parameter="method" 这里指定了我要访问的标识,所以method=add就会去找add方法,这可以随便改<struts-config> <form-beans>
    <form-bean name="UserForm" type="com.lzt.struts.form.user.UserForm" />
    </form-beans> <action-mappings>
    <action path="/userAction" type="com.lzt.struts.action.UserAction"
    name="UserForm" scope="request" validate="false" parameter="method">
    <forward name="success" path="/user/success.jsp" />
    </action>
    </action-mappings></struts-config>
    jsp
    Form里面的属性类型要对应好<body>
    <form action="userAction.do" method="post"
    enctype="multipart/form-data">
    <input
    type="hidden" name="method" value="add">
    <TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0"
    style="width: 580px;">
    <TBODY>
    <TR>
    <!-- 这里是添加、编辑界面的标题 -->
    <td align="center" class="tdEditTitle">添加或更新流程信息</TD>
    </TR>
    <TR>
    <td>
    <!-- 主输入域开始 --> 请选择上传的流程文件: <input type="file"
    name="processDefinition" /> <br> 请选择上传的流程图片: <input
    type="file" name="processImage" /> <br> <input type="submit"
    name="submit" value="上传" /> <!-- 主输入域结束 -->
    </td>
    </TR>
    </TBODY>
    </TABLE>
    </form>
    </body>
    我的访问链接:http://localhost:8080/Struts1Test/userAction.do结果可以访问到 add方法。测试完毕。
      

  11.   

    直接访问jsp点击提交可以进入add方法,你还是看看你的配置是不是哪里有问题,不行就debug一下看看具体代码怎么走的
      

  12.   

    配置没有问题。

    enctype="multipart/form-data"

    请选择上传的流程文件:<input type="file" name="processDefinition" />
    <br>
    请选择上传的流程图片:<input type="file" name="processImage" />

    去掉,直接点击上传就可以执行add方法了。为什么?
      

  13.   

    UserForm类里面的第2、3个属性不应该是File类型,而应该是FormFile类型。
      

  14.   

    enctype="multipart/form-data" 记得这种form提交后台是获取不到的
      

  15.   

    参考一下这个http://wj196.iteye.com/blog/1628465 或者http://www.cnblogs.com/kenkofox/archive/2011/03/26/1996258.html
      

  16.   

    终于解决了,是struts的jar包问题。不要使用struts 1.2,用1.3就没问题了。