Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing javascript variables to jsp

Status
Not open for further replies.

lowbk

Technical User
Nov 26, 2001
162
SG
is it possible to pass javascript variables to jsp variables?
eg within the same page

var javascripthrn = prompt("Enter hrn");

then i need to process this input within jsp

<%
String jsphrn;
%>

how to assign javascripthrn to jsphrn?
 
Did you ever get your javascript to jsp variable question answered ? I need to same info .
 
This is not possible, nor is it logically sensible.

Javascript code runs on the client (in other words after the page is downloaded).

JSP code runs on the server (in other words before the page is downloaded).

The only thing you can do is have your javascript submit a request to a JSP and pass the necessary parameters along with the request.
 
OK - Thanks. Even if I specify serverside in javascript ?

How about this - I am getting the javascript variables from a call to a servlet.

(e.g)
<HEAD>
<SCRIPT LANGUAGE=&quot;Javascript&quot; SRC=&quot; </SCRIPT>
</HEAD>

It is returning the javascript .

var username = &quot;xxxxx&quot;, etc..

Can I grab this information in the jsp and do string manipulation to get by data, then store in a variable ?

I can handle the string manipulation but not sure how the get this data returned from the servlet into my jsp.

I am using:

<jsp:include page=&quot; flush=&quot;true&quot; />

Then what do I do ?

All of you help has been great. I am looking for option other then posting the javascript as it may be a security problem.

Thansk -
 
About posting javascript.

This should never present a security problem because any visitor to your page can ALWAYS get at the javascript. Disable right-click? I can still get to it. You will have MAJOR security problems if you store anything that must not be seen in javascript.
 
hi,
i am having an identical problem which is:
i need to pass a javascript variable value into a jsp variable.
Because, the jsp variable is an argument of a jsp function.
is there a way to do this, is it possible from HTML?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top