Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using jsp tags in javascript

 
lakshmi ananthamurthy
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I had this problem in our project.
I needed to access a value in the <SCRIPT> tag in a jsp which I was obtaining from the request object.
Now, I needed to put a string dynamically in the page only if javascript was enabled and add that value to a href tag, calling a servlet and passing this value as a get variable.
But when I tried to access the variable using the jsp expression
<%= var name%>, the view source of the file showed the value, but on clicking the link, the servlet got called and did not function the way it should.
TO be precise the following code did not work fine:
<% String varname = (String)request.getParameter("somevar");%>
<BODY>
<SCRIPT>
document.write("<A HREF = \"Servletname?Variable=<%= varname%>\"></A>");
</SCRIPT>
</BODY>
But when I put all the above in out.println statements, it worked perfectly fine.
Any ideas how to make the above work without putting it into the out.println tags?
 
manav kher
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well if u can see it in the source then it should work,..the only reason it won't work is if the link itself is wrong
and when u say the servlet did not do what was intended do u mean it did not execute the service method (doPost and doGet) because thats what usually is implemented...if that is the case then these methods only get called when Posting or "GET"ing a Form ...i guess u knew that anyway
-manav
 
lakshmi ananthamurthy
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thats the funny thing, it would not work even when the value was reflected in the source, but when I put the same thing inside out.println statements, the link got called and the servlet worked just fine.
lakshmi

 
Desai Sandeep
Ranch Hand
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lakshmi,
Try to encode the URL and see what you get.

Let me know the results.
Thanks,
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 26, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic