| Author |
JSP inside JavaScript?
|
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
Is it possible to include a JSP tag inside javascript? I am doing this: <SCRIPT> function getURL(thisURL){ <%session.setAttribute("myURL",thisURL);%> } </SCRIPT> I tried coding it like this, but it fails to load the rest of JavaScript. thanks, Alex
|
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 11862
|
|
Remember - Javascript executes on the browser, JavaServer Pages execute on the server. You can have JSP write Javascript into the contents of a page, but a JSP tag cant be executed on the browser. What exactly are you trying to do? Bill
|
 |
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
I am trying to record a url that was clicked from my JavaScript menu in a browser. I call getURL() through onClick in my <a href> tag and try to set url string to a session variable. All of this is done to record when applets were accessed by a user [ see my earlier post on this forum ]. thanks, Alex
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50691
|
|
Did you actually LOOK at the HTML that was sent to the browser? If you would, you'd see that what you are generating is not valid JavaScript and that is why the rest of the JavaScript isn't loading correctly. hth, bear
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
Yes, I see that. Do you have any suggestions on how can I see which url user chose and transfer that link to JSP/Servlet. Or is this better accomplished thru Appache? Also, I've seen examples on the web where there were examples of what I am trying to do. Not sure why code was posted if it does not work... thanks, Alex
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50691
|
|
I'm not really clear on what you are trying to accomplish. The current URL is already available to JavaScript as document.location. What beyond that are you trying to do? bear
|
 |
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
I have a JavaScript menu that has links to various applets on the server. When a user logs in, he is presented with this menu and can choose different applets to go to. I thought about using url encoding to record a session id that a user was given when he loged in, and use this session id to retrieve information about where user went. I tried to user url encoding in conjunction with JavaScript to display <a href="myApplet.jsp;jsessionid=44jH10Xz">applet</a>, but as you mentioned above it would not work. What I am trying to accomplish with this is a log file that would display userId, time link was accessed and applet that was accessed. The first two are easy, but the last one is the one I have problems with. If I had just static urls in HTML page, I could encode url with session id easily, but here I have JavaScript driven menu and this JavaScript is what generates links to applets. Hope this is clear. thanks, Alex
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 11862
|
|
If I understand you correctly, it seems to me you don't want the initial page to have real URLs but some sort of code that gets submitted back to your servlet. The servlet records the usage and does a redirect to the applet. Bill
|
 |
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
Yup, exectly. However, my urls are JavaScript based and I am not sure if this will play nicely with JSP/Servlet architecture. thanks, Alex
|
 |
 |
|
|
subject: JSP inside JavaScript?
|
|
|