It's not a secret anymore!*
The moose likes Servlets and the fly likes using jsp tags in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "using jsp tags in javascript" Watch "using jsp tags in javascript" New topic
Author

using jsp tags in javascript

lakshmi ananthamurthy
Greenhorn

Joined: Apr 26, 2001
Posts: 5
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

Joined: Nov 21, 2000
Posts: 98
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

Joined: Apr 26, 2001
Posts: 5
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

Joined: Apr 02, 2001
Posts: 1157
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).]


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using jsp tags in javascript
 
Similar Threads
Problem with script tag
reading data from jsp page to another jsp page using request.getParameter
Javascript failing to evaluate?
Servlets & javascript
Problem with closing script tag