Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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
如何在javascript中为函数指定jsp路径_Javascript_Java_Jquery_Jsp - Fatal编程技术网

如何在javascript中为函数指定jsp路径

如何在javascript中为函数指定jsp路径,javascript,java,jquery,jsp,Javascript,Java,Jquery,Jsp,我有一个jsp页面,它是 addSource.jsp 出现在eclipse中,如图所示。 现在我的问题是我有一个javascript函数,我必须在其中提供addSource.jsp,这样它就可以在单击按钮时从当前jsp页面移动到该页面 function addRow(type) { if (type == '') { alert("Field is empty"); } else {

我有一个jsp页面,它是

addSource.jsp

出现在eclipse中,如图所示。

现在我的问题是我有一个javascript函数,我必须在其中提供addSource.jsp,这样它就可以在单击按钮时从当前jsp页面移动到该页面

 function addRow(type) {  
         if (type == '') {
                alert("Field is empty");
            }
         else {
         var table = document.getElementById('my_table'); //html table
         var rowCount = table.rows.length; //no. of rows in table
         var columnCount =  table.rows[0].cells.length; //no. of columns in table          
         var row = table.insertRow(rowCount); //insert a row            



         var cell1 = row.insertCell(0); //create a new cell           
         var element1 = document.createElement("input"); //create a new element           
         element1.type = "text"; //set the element type 
         element1.setAttribute('id', 'source'); //set the id attribute 
         element1.setAttribute('name','source'+rowCount);
         element1.setAttribute('value',type);
         cell1.appendChild(element1);

         }


         }

    function generate1() {
             var table = document.getElementById('my_table'); 
             var rowCount = table.rows.length;
             alert(rowCount);
             var f = document.form;
             f.target="";
             f.method="post";
             f.action= 'addSource.jsp?rowCount='+rowCount;



         }  

     <form id="form">

                       <input type="text" id="origin" name="element"/>




                      <table id="my_table">
                                <thead><tr>

                                        <th>Source</th>


                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>





                        <input type="button" value="Add row"  name="add" onClick="addRow(document.forms[0].element.value)"  />
                        <input type="submit" value=" Save" />
您可以使用location.href将id添加到表单中,例如formId,并使用如下内容:

<script type="text/javascript">
    document.getElementById("formId").onclick = function () {
    location.href = "addSource.jsp";
};
控制器

@RequestMapping(value = "/Source",params="Save", method = RequestMethod.POST)
    public String source(Model model,HttpServletRequest req,HttpServletResponse res,@RequestParam("source") List<String> ola) {
        System.out.println("size is:" +ola.size());
        for(int i=0; i<ola.size() ;i++) {
            String srh = ola.get(i);
                    System.out.println("srh value is:" +srh);
        }

        return "redirect:/createPoints";
    }

显示你只需要一个点击事件在你的形式?考虑使用MVC@ScaryWombat您的意思是创建类文件,而不是使用jsp??POST/GET to servlets和使用jsp for Display这里我想的问题是我已经动态添加了文本框值。我曾想过发布到servlet中,但找不到一种方法来发布10个或15个动态文本框值。为了更好地理解,我编辑了我的文章。请参阅itdocument.getElementByIdformId.onclick=function{var table=document.getElementById'my_table';var rowCount=table.rows.length;alertrowCount;location.href='addSource.jsp?rowCount='+rowCount;};我将编辑该问题,以获得更多理解能力。您使用的document.getElementById是document.getElementById的两倍。这行不通。只使用您想要处理事件的元素。这里我有一个按钮onClick,它是AddRow。一旦我点击它,就会动态地创建文本框和值。因此,我又使用了一个document.getElementById,这样就可以得到创建了多少textbox值的rowCount。
@RequestMapping(value = "/Source",params="Save", method = RequestMethod.POST)
    public String source(Model model,HttpServletRequest req,HttpServletResponse res,@RequestParam("source") List<String> ola) {
        System.out.println("size is:" +ola.size());
        for(int i=0; i<ola.size() ;i++) {
            String srh = ola.get(i);
                    System.out.println("srh value is:" +srh);
        }

        return "redirect:/createPoints";
    }