Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

Jsp & JavaScript

 
kanth varada
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Friends,

I declare a variable in Jsp

<%! int x=0; %>

and i declare one more variable in JavaScript.

var i=1;

what i want is...how can assign the javascript variable value to jsp variable.

that is how can assign 'i' value to 'x'......


Pls help me friends.........
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
I thought that we'd already talked about his
You cannot.
 
Shilpa Asuthkar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
there is one solution to ur problem.....
store the javascript variable in a form field and then set it to the variable of in the jsp.... this form is a dummy form which on submit goes to javascript and the back to the same form
for example.......

<html>
<head>
<script language="javascript">
function meth()
{
var i=0;
i=i+1;
document.getElementById("t1").value=i;
}
</script>
</head>
<body>
<%! int x=0; %>
<form name="myform" action="temp1.jsp" onSubmit="return meth()">
<input type="text" name="t1" value='<%=request.getParameter("t1") %>' >
<input type="submit" value="submit" >

</form>
<% if(request.getParameter("t1")!=null) x=Integer.parseInt(request.getParameter("t1")); %>
<%= x%>
</body>
</html>

tough we r not supposed to use scripting in jsp but thats how u want want to set the value of x.....
hope this will help u.......
let me know...

regards,
Shilpa
 
kanth varada
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Shilpa Asuthkar ,

thanks for sending me the stuff..but when iam displaying the t1 value

<%=request.getParameter("t1")%> it is displaying null every time..that means it is not storing the i value in

i=1;
document.getElementById("desc").value=i;


the steps what i wrote is.....

<script language="javascript">
var i;

if(some logic)
{
i=1;
document.getElementById("desc").value=i;
}
else
{
i=0;
document.getElementById("desc").value=i;
}
</script>
<input type="hidden" value=<%=request.getParameter("desc") %> name="desc">
<%=request.getParameter("desc")%>

-----------------------It is displaying Null.....

pls let me know the mistakes iam doing.......
 
    Bookmark Topic Watch Topic
  • New Topic