File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "using jsp tags in javascript" Watch "using jsp tags in javascript" New topic

using jsp tags in javascript

lakshmi ananthamurthy

Joined: Apr 26, 2001
Posts: 5
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");%>
document.write("<A HREF = \"Servletname?Variable=<%= varname%>\"></A>");
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
lakshmi ananthamurthy

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.

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.
Sandeep Desai

  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:
subject: using jsp tags in javascript
It's not a secret anymore!