File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a scriptlet value into JS function?

 
auvrm papu
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for ex:


doing this,



gave me the alerted value as



instead,

if the company.getId() --> 30
when I do like this, how to get the value 30 inside the function?

i want


Thanks!
[ April 10, 2007: Message edited by: Ais Kaly ]
 
Scott Escue
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ais,

What you're describing works for me, i.e. I get the value of the java variable in my alert. Are scriptlets working at all on your page? Can your simply write out a variables value to the page body using a scriptlet? It could be possible that scriptlets are disabled for your application. Do you have anything similar to the following in your web.xml:

There may be other ways to disable scriptlets at the page or container level.
 
auvrm papu
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott,

I don't have the code mentioned in my web.xml

I tried with System outs...and the values are coming out well.
So, I'm sure scriptlets are enabled...

any help pls?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are seeing uninterpreted scriptlet code in your HTML, something is wrong in your setup not in your code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ais Kaly:
for ex:


"ex" is not a word. Please use only real words such as "example" when posting to the forums. Please read this for more information.
 
auvrm papu
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set up???
can you give me pointers? where exactly I can verify this?
 
auvrm papu
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually these 2 worked:


Can anyone know why this is not working in html:text?



Moderator: can you please move this to respective forum?
 
auvrm papu
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following worked for html:text as well!

onblurr='<%="check("+company.getId()+")"%>'

Source : http://forum.java.sun.com/thread.jspa?threadID=402026&messageID=1755013
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, of course. I missed that fact that this was in a custom tag. So I take it bake... the problem is with your code.

You cannot use a scriptlet expression as part of the attribute to a custom action. It must be all of the attribute, or none.

EL expressions have no such restrictions, which is just one of the many reasons that you should no longer be using scriptlets if you are using a JSP 2.0 container.
[ April 10, 2007: Message edited by: Bear Bibeault ]
 
panchatcharam siva
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<%
String url="http://localhost:8080/ui-web/images/image.png";
request.setAttribute("Url", url);

%>
<script>
function myFunc(){
var tempUrl= "<%= request.getAttribute("Url") %>" ;
}
</script>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to hard-code the value into the JSP, why not just hard-code it into the JavaScript code?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic