-1

I want to pass a java script var to script let in jsp. i tried many things but not working anything.can anyone tell me a working solution.

i have tried How do I pass JavaScript values to Scriptlet in JSP?

0

1 Answer 1

0

the way this other post stays, is the correct one.

1- create an ajax call (in Javascript) in your webpage to send your desired params to another page.

2- create a page (in jsp) where you request the data sent by the #1.

That's the correct way to go.

#1 Here's an example on how to make an ajax call, you need this on step #1, if your using jquery is simple as:

String data1 = "myData1";
String data2 = "myData2";
String your_jsp_page_to_request = "myJspPage.jsp";

$.post(your_jsp_page_to_request,
    { param1: data1, param2: data2 },
    function(data){
       alert("Data Loaded: " + data);
    }
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

#2 Then in your jsp you need to request the data sent, just using:

String data1 = request.getParameter("param1");
String data2 = request.getParameter("param2");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.