0
<body>
    <input type="button" value="page1">        
</body>

This is my page1.jsp page,when i click on this i need to get the value in result.jsp page without changing the browser header.

in my project i have 4 jsp pages named page1.jsp,page2.jsp,page3.jsp and page4.jsp

when i click on any page, result should come in result.jsp.

suppose if i clicked on page2 result should come in result.jsp only,all pages have same input button value are page1,page2,page3 and page4

http://localhost:8080/TestProject/result.jsp

This is my browser header. thanks your help.

Aaron Butacov
  • 32,415
  • 8
  • 47
  • 61
  • [read parameters passed by one jsp to another](http://stackoverflow.com/a/20761294/1031945) – Aniket Kulkarni Mar 13 '14 at 13:56
  • possible duplicate of [How to use data in one jsp page to another jsp page](http://stackoverflow.com/questions/5941440/how-to-use-data-in-one-jsp-page-to-another-jsp-page) – jmail Mar 14 '14 at 04:23

2 Answers2

1

Have a look at jQuery AJAX, Its used to GET/POST data values to any page from Client to server. Without redirecting user to other page (changing URL in address-bar)

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script>
        $(document).ready(function(){ 
            $("button").click(function(){
                var value=$(this).val(); //it will get value of clicked button

                $("#result_div").load('result.jsp?param='+value); //it will make ajax call to result.jsp by GET method
            });
        });
        </script>

    </head>
    <body>
        <input type="button" value="value1" />

        <div id="result_div">
            JSP Result will be loaded here.
        </div>
    </body>
</html>

In this example, I've use GET method and passed parameter named param that you'l have to read in result.jsp. Whatever result is given by result.jsp It will be loaded in #result_div

Useful Links:

https://api.jquery.com/load/

https://api.jquery.com/jQuery.get/

https://api.jquery.com/jQuery.post/

http://www.w3schools.com/jquery/jquery_ref_ajax.asp

https://api.jquery.com/jQuery.ajax/

Ravi Dhoriya ツ
  • 4,435
  • 8
  • 37
  • 48
  • could you explain the same logic using this jsp,please. –  Mar 13 '14 at 13:56
  • Actually JSP is not everything. After all what you need is facility from Client side. For that you'l need to write some code in client-side scripting. jQuery is very easy, you can make async calls to server and get/post data. If you want sample code, I can help you with that. – Ravi Dhoriya ツ Mar 13 '14 at 13:58
  • Before I write, please clarify, What value you want to pass in your `result.jsp` page? Is it value="page1" of button? And also clarify which method you are handling in your JSP? (GET or POST) – Ravi Dhoriya ツ Mar 13 '14 at 14:06
  • use any get/post,when i click on page1,value of page1 should display in result.jsp,and if i click on page2 ,value of page2 should display in reult.jsp,vice versa, –  Mar 13 '14 at 14:09
  • i dont want to use jquery/any other technique,i want to use only jsp,thanks for your help –  Mar 13 '14 at 14:21
  • Ok, Then its your choice. Sometimes we should understand client-side scripting and server side scripting. Anyways.. GOod luck – Ravi Dhoriya ツ Mar 13 '14 at 14:23
0

You can use:

request.getParameter("<input_name_given_in_previous_page>");

and for sending parameters, use form tag in HTML.

example:

index.jsp

<html>
<body>
<form name="frmLogin" action="redirect.jsp" method="post">
<input type="text" name="user_name">
<input type="submit" value="Submit" name="login_submit">
</form>
</body>
</html>

redirect.jsp

<%
    //it's demo only. 
    String u_n=request.getParameter("user_name");
    out.println("Hello "+u_n);
%>
Ysr Shk
  • 224
  • 5
  • 16