| Author |
converting variable types
|
payal kapadia
Greenhorn
Joined: Feb 08, 2005
Posts: 10
|
|
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
Joined: Aug 15, 2004
Posts: 2874
|
|
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
Joined: Jan 24, 2005
Posts: 489
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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 ]
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
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.
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
It was number one, actually: http://www.coderanch.com/t/359805/Servlets/java/Top-Servlet-JSP-misconceptions
|
 |
pradeep jaladi
Ranch Hand
Joined: Nov 21, 2004
Posts: 65
|
|
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
|
Pradeep.Jaladi
|
 |
 |
|
|
subject: converting variable types
|
|
|