Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Struts 1.2,从表单传递参数_Java_Html_Forms_Jsp_Struts 1 - Fatal编程技术网

Java Struts 1.2,从表单传递参数

Java Struts 1.2,从表单传递参数,java,html,forms,jsp,struts-1,Java,Html,Forms,Jsp,Struts 1,所以最近我开始在我目前工作的公司里开发一个大型的旧应用程序。它是用Spring编写的,使用struts 1.2作为控制器——我对这项技术并不十分熟悉。我的任务是添加多个接受选项-有一个接受单个发票的选项。因为我不知道struts到底是如何工作的(相信我,这个应用程序的架构完全是意大利面条),我想使用这个单一的接受动作来进行多重接受——将id传递给方法,如果请求循环中有多个id,则通过所有id并通过接受过程(这也是相当长和相当不可读)的每个id 问题是-表单似乎没有将id传递给url-在方法中,我

所以最近我开始在我目前工作的公司里开发一个大型的旧应用程序。它是用Spring编写的,使用struts 1.2作为控制器——我对这项技术并不十分熟悉。我的任务是添加多个接受选项-有一个接受单个发票的选项。因为我不知道struts到底是如何工作的(相信我,这个应用程序的架构完全是意大利面条),我想使用这个单一的接受动作来进行多重接受——将id传递给方法,如果请求循环中有多个id,则通过所有id并通过接受过程(这也是相当长和相当不可读)的每个id

问题是-表单似乎没有将id传递给url-在方法中,我从请求url检索id数组。struts中有没有通过url传递参数的方法

它看起来或多或少像这样:

表格:

<html:form action="/invoice_processing" method="get" styleClass="form">
   <c:if test="${not empty invoices_list_with_dynamic_checkboxes}">             
      <jsp:include page="/WEB-INF/jsp/invoices/dynamic_invoices_list_with_checkboxes" flush="true"/>
   </c:if>
</html:form>

struts.xml

<action path="/invoice_processing"
   type="pl.blah.blah.InvoiceProcessor"
   name="invoice_processing_form" scope="session" validate="false">
   <forward name="executeTask" path="/i_do_not_matter.do" />
</action>

编辑-添加表格和方法“发票列表和动态复选框”


我不在乎身份证
我不在乎
我不在乎
选中复选框
它所使用的方法(注意:ActionContext是一个自制的类,它不实现扩展任何上下文类的任何接口-尽管它通过getRequest()检索请求url-尽管它提供了类似invoiceProcessing.do的功能)

protected void execute(ActionContext ActionContext)引发异常{
HttpServletRequest=actionContext.getRequest();
List listOfIdString=new ArrayList();
listofidint=newarraylist();
InvoiceEditionForma=(CFakturaEdycjaForm)actionContext.getForm();
字符串[]idArray=request.getParameterValues(“checkboxGroup”);
如果(idArray!=null&&idArray.length>0){
listOfIdString=Arrays.asList(idArray);
for(字符串currentId:listOfIdString){
add(Integer.parseInt(currentId));
}
for(整数currentId:listaIdFakturaInt){
发票=invoiceLogic.findInvoiceById(currentId);
(此处为验收流程)
}
}

所有这些名称都用英语重命名-我无法复制粘贴所有这些代码,因为它非常长,基本上有可以正常工作的内容,这不是一个问题。问题在于检索表单本身提交的id。

使用复选框发布
动态发票列表
页面和操作方法。添加了该方法还有列表!我没有找到您提到的名为
id
的任何参数
String[]idArray=request.getParameterValues(“id”);
而您的表单中有
checkboxGroup
中的值。您应该尝试使用
String[]idArray=request.getParameterValues(“checkboxGroup”)
在您的操作中。重写时出现了一个小错误-整个应用程序都是用波兰语编写的,所以我不想与之区分,当然我也不想用波兰语发布代码;)不过我会编辑这个!
<div class="table">
    <table class="table_list_highlight">
        <thead>
            <tr>    

                <th rowspan="2">I do not matter ID</th>
                <th rowspan="2">I do not matter</th>
                <th rowspan="2">I do not matter</th>
                <th rowspan="2">Check the checkbox</th>

            </tr>

        </thead>    
        <c:forEach var="singleInvoice" items="${invoicesThatAreDeclaredBeforeAndWork}">
            <tbody>
                <tr>
                    <td rowspan="2"><c:out value="${singleInvoice.invoice.amount}"/></td>
                    <td rowspan="2"><c:out value="${singleInvoice.invoice.date}"/></td>         
                    <td rowspan="2"><c:out value="${singleInvoice.invoice.whatever}"/></td>         
                    <td rowspan="2"><input type="checkbox" name="checkboxGroup" value='${singleInvoice.invoice.id}'></td>

                </tr>           
            </tbody>
        </c:forEach>
    </table>
</div> 
protected void execute(ActionContext actionContext) throws Exception {

    HttpServletRequest request = actionContext.getRequest();
    List<String> listOfIdString= new ArrayList<String>();
    List<Integer>listOfIdInt= new ArrayList<Integer>();
    InvoiceEditionForm forma = (CFakturaEdycjaForm) actionContext.getForm();
    String[] idArray = request.getParameterValues("checkboxGroup");

    if(idArray != null && idArray.length > 0) {

        listOfIdString = Arrays.asList(idArray);

        for(String currentId: listOfIdString) {

            listOfIdInt.add(Integer.parseInt(currentId));

        }

        for(Integer currentId: listaIdFakturaInt) {

            Invoice invoice = invoiceLogic.findInvoiceById(currentId);

            (Acceptance process goes here)

        }

}