Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting variable types

 
payal kapadia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

Im really stuck in here.

I am using both javascript as well as jsp together. I need some way so that i can convert 'var' which is used in javascript to type 'String ' that is used in Jsp.
Is there some way to do this.

thanks,
payal
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by payal kapadia:
Im really stuck in here.

I am using both javascript as well as jsp together. I need some way so that i can convert 'var' which is used in javascript to type 'String ' that is used in Jsp.
Is there some way to do this.


Both, javascript and jsp, are different animals.

Ok Whatever.
By the way why do you want to do this?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp is compiled and the contents evaluated in the server first and then on the browser, javascript is evaluated.
This means that u could use a jsp variable in javascript. see a basic usage below.



What this also means is that it would be pretty impossible to do it the other way around i.e use a javascript variable as the value of a jsp variable.

ram.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A useful habit to get into when starting out as a web programmer is to always view and debug your javascript/html code by using your browser's "view source" feature. By doing so, you get used to seeing the HTML/Javascript code without the JSP or ASP or PHP tags. This reinforces the concept that HTML/Javascript is the result from the execution of your server side code and that the two never get interpreted at the same time (or in the same place).

To answer your original question: If you need to get values, changed in the client, back up to the server you will need to re-post them in an HTML form.
You can use Javascript to alter the <input..> fields of your form and to submit the form if you like.
[ February 09, 2005: Message edited by: Ben Souther ]
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good suggestion! That's one thing that folks don't really understand too well when starting out. I don't know if that was included in the "Top 10 List" that was on one of these forums not too long ago, but it should be.
 
pradeep jaladi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yesterday i had seen this question and tried back in home in differently.

1) By pushing values in javascript to cookie and retriving back in jsp
" which the poolish one i did Because cookies in javascript are
different from and jsp ".

2) By putting the java script value to the hidden filed and pushing back the
to server and assigning the value"


After pushing the values
String val = <%= request.getParameter("hide") %>
// Hidden textfield Value
<% request.setAttribute("jspvalue", val) %> // JSP Value

Error:val does not Contail " quotes in line <% request.setAttribute("jspvalue", val) %>"
3) At last i tried to push the values in a temperory file and get it backto the jsp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic