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
posted
0
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
posted
0
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
posted
0
Hi Lakshmi, Try to encode the URL and see what you get.