• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting variable types

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was number one, actually:
https://coderanch.com/t/359805/Servlets/java/Top-Servlet-JSP-misconceptions
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic