Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Getting Paramter value passed in Java Script function to JSP code

Posted on 2006-06-05
3
Medium Priority
?
312 Views
Last Modified: 2010-04-01
Hello and how is everyone. Can I do get a value from a JavaScript parameter that is passed from my web form and get that into my JSP code variable. For ex:

JSFunction(MyVariable){

var JSVariable =  var nodeId2 = document.getElementById(nodeId).value;

<%
 Now in my JSP code I want to get that value of JSVariable.

%>

Possible?
0
Comment
Question by:Corey_819
  • 2
3 Comments
 
LVL 5

Expert Comment

by:jpolin1
ID: 16836560
Javascript is client-side, scripplet code is server-side, you can't really intermingle them like you are trying to do.

What you need to do, is take the javascript variable, and pass that along to another page via a form-post or on a query string, then in the next jsp you hit you can process the value.


<-- original page -->
myJSFunction(){

    var JSVariable =  var nodeId2 = document.getElementById(nodeId).value;
    location.href = "/myNextJsp.jsp?val="+JSVariable;

}


<-- myNextJsp.jsp --->

<%
   
    String myVal = (String)request.getParameter("val");
 
     .... //do whatever
   
     ....

%>
0
 
LVL 1

Author Comment

by:Corey_819
ID: 16836887
Okay it is not null no more, but it is nothing just blank

 String SelectedNodeId =  (String)request.getParameter("val");

however the link is as:

http://localhost:8084/TandDRegistratonForm/index.jsp?val=#1 LTW-CLINICAL DECISION MAKING


???
0
 
LVL 5

Accepted Solution

by:
jpolin1 earned 160 total points
ID: 16841423
OK, thats because the parameter, val=something cannot have spaces in it, and I suppose that the pound sign maybe an issue too.

In the javascript that creates the link, do something like this:

myFunc(){
  var JSVariable =  escape(document.getElementById(nodeId).value);
   location.href = "/myNextJsp.jsp?val="+JSVariable;

}

you have to encode the spaces in your parameter, the resulting val= should have some ampersands and maybe "+" signs.
That should work, I'm not sure if you will have to decode it in the scriplet, if you do user URLDecoder:
http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLDecoder.html

Let me know if that works




0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Machine Learning is one of the profound applications of AI and therefore, just like AI, it is surrounded by myths and fears. Check out these facts about ML that demystify the related myths.
"Day by day nothing changes but when u look back, everything is different". That quote precisely describes today’s digital era. For example, you may not have noticed the change, but Voice Search is now all around us.
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question