Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP inside JavaScript?  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, exectly. However, my urls are JavaScript based and I am not sure if this will play nicely with JSP/Servlet architecture.
thanks,
Alex
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!