ravi
ravi

Reputation: 75

How to call action with parameters of JSP Servlet from JavaScript?

function printthis()
{ 
 var content_vlue = document.getElementById('print_content').innerHTML;
 var target= 'printValue?value1='+content_vlue;
 document.forms[0].action = target;
 document.forms[0].submit();
}

<div id="print_content">hello i am good</div>

For frontend I am using JSP. While executing this code to get the value in servlet

String msg = request.getParameter("value1");

While executing this code the browser url changes to printValue?

But I am unable to get the value of value1

Please suggest me...

Upvotes: 0

Views: 2736

Answers (2)

someone
someone

Reputation: 6572

Seems you are missing value1='+content_vlue from the request try this and see

var target= "'printValue?value1="+content_vlue+"'";

Upvotes: 1

Neeraj
Neeraj

Reputation: 1816

Create a hidden variable inside your form like this

<form ..>
    ....
    <input type="hidden" id="value1" name="value1"/>
</form>

and modify javascript function to this .

function printthis()
{ 
 var content_vlue = document.getElementById('print_content').innerHTML;
 document.getElementById('value1').value  = content_value;
 var target= 'printValue';
 document.forms[0].action = target;
 document.forms[0].submit();
}

Hope this will work for you.

Upvotes: 0

Related Questions