简体   繁体   English

使用jQuery在两个jsp页面之间传递数据

[英]passing data between two jsp pages using jquery

I know this question seems already asked.. But i surfed through the websites and i did not get any clarification. 我知道这个问题似乎已经被问到了。。但是我浏览了网站,但没有得到任何澄清。 Here is my question. 这是我的问题。 I have two web pages. 我有两个网页。 Call them as page1.jsp and page2.jsp. 将它们称为page1.jsp和page2.jsp。 I am having a table in my page1.jsp. 我的page1.jsp中有一个表。 Please refer the image 请参考图片 请参考图片

And in my page2.jsp i am having an input field like in the following image 在我的page2.jsp中,我有一个输入字段,如下图所示 在此处输入图片说明

Now I need to display the the respective docId in the textarea which i am clicking in the page1.jsp. 现在,我需要在单击page1.jsp的文本区域中显示相应的docId。

For example if i am clicking 00001 in page1.jsp i needs to redirect to page2.jsp and 00001 should be updated textarea of in page2.jsp 例如,如果我单击page1.jsp中的00001,则需要重定向到page2.jsp,并且应将page2.jsp中的00001更新为textarea

the script i used in page1.jsp is 我在page1.jsp中使用的脚本是

$('.pending_list').click(function(){
            var row = $(this).closest("tr"); 
            var text = row.find(".pending_list").text(); 
            alert(text);
            var DocNo = text;
            $('.pending_list').attr({
                href:"${loginbean.contextPath}/effortloading/search"

            });         
        });

Here is my page2.jsp 这是我的page2.jsp

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                            <div class="row padding6">
                                                <div
                                                    class="col-lg-4 col-md-4 col-sm-4 col-xs-12 margintop8  rq-field">
                                                    <!-- for field required notification-->
                                                    <spring:message text="Doc No" />
                                                </div>
                                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                    <form:input id="docID" path="DOC_ID" name="DOC_ID" type="text"
                                                        class="form-control" />
                                                    <form:errors path="userTitle" class="control-label" />
                                                </div>
                                                <div class="col-lg-2 col-md-2 col-sm-2 col-xs-12"></div>
                                            </div>
                                        </div>

Controller 调节器

@RequestMapping(value = "/effortloading/search", method = RequestMethod.GET)
    public String effortloadingsearch(@Valid @ModelAttribute("loginbean") Loginbean loginbean,EffortLoadingBean effortBean, Model model,BindingResult result){
        model.addAttribute("effortloadingedit", effortBean);
        return "EffortLoadingSearch";
    }

I hope my question is understandable. 我希望我的问题是可以理解的。 Thanks in advance 提前致谢

As a bare minimum you can pass your docId in the url itself from page1 and then later in page2 you can get it from your url and put it in the search area. 作为最低限度,你可以通过你docId在URL中从第1页 ,然后在第2页以后你可以从你的网址,以获取它,并把它在搜索区域。

A little code to understand 一点代码了解

In page1 : 在第1 页中

    $('.pending_list').click(function(){
        var row = $(this).closest("tr"); 
        var text = row.find(".pending_list").text(); 
        alert(text);
        var DocNo = text;
        $('.pending_list').attr({
            //SEND YOUR DOCID IN THE URL
            href:"${loginbean.contextPath}/effortloading/search?docId=" + GET_ID_HERE
        });         
    });

在page1.jsp中形成URL 00001时 ,您可以附加查询参数,并且该查询参数可以在第二页中用于填充文本区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM