• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i call a Java function within JSP

 
Ayeda AngeL
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am having this silly problem that making me go crazy..
I have a java function like following
function Chr(CharCode)
{
return String.fromCharCode(CharCode);
}
and then i wanna call that function within my jsp file
str = JavaScript:Chr(96+i)+"1";
tst = JavaScript:Chr(96+i);
but that aint working...
Please could you help me here...
Thanks
Ayeda
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused whether you mean "Java" or "JavaScript" in your message above.
It's important to remember that JavaSCript is usually executed by the browser, after the page has been generated and sent by the server. [i]JSP and [/i]Java[/i] code, on the other hand, happen on the server when the page is being generated, before it is sent back to the browser.
So, can you clarify whether you want to so something while the page is being generated, or after it has been sent to the browser?
 
Ayeda AngeL
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry...
Yes you r rite, its a Java Function. but i want to call it within the jsp
please can you help??
 
Ayeda AngeL
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehehhee.... i did it again....
I meant Java Scripts.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the whole point is that the JSP code is executed on the server when the page is built. The page is then sent to the browser. Only then (long after the JSP code finished running, and on a different machine!) is any JavaScript code executed.
You simply can not run JavaScript code "within" the Java code of a JSP.
Can you give any more details of what you are trying to accomplish with this? Maybe we can help offer alternative ways of doing it.
 
prabhu chetty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ayeda AngeL:
Hi All,
I am having this silly problem that making me go crazy..
I have a java function like following
function Chr(CharCode)
{
return String.fromCharCode(CharCode);
}
and then i wanna call that function within my jsp file
str = JavaScript:Chr(96+i)+"1";
tst = JavaScript:Chr(96+i);
but that aint working...
Please could you help me here...
Thanks
Ayeda

Hi
use the declaration tag in the jsp and declare the method in that and call the method as u call in normail java code
 
Ayeda AngeL
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi prabhu chetty
mmmmm..... you kinda got me confused here.. can u explain more.. or give me an example on how to do it?
thanks zillion times...
 
Ayeda AngeL
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank
thanks for your reply..
well the fuction Chr is a ready built function in oracle like instr, i was requested to convert a page from pl/sql(my fav) to jsp (which am starting to hate!) during the conversion, i found this line str := chr(96+i)||'1';
now on converting it, i thought of creating a javascript which does the same thing.the Chr Returns a String containing the character associated
with the specified character code.
but its aint working...
Hoping you can help me...
thanks...
Ayeda
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. So you just seem to want to get the chracter specified by an ASCII number. If you need to do that during page building, it's simple enough to do in Java. One thing you need to be a little careful about is that Java is a modern language whichg supports unicode characters with more than 8 bits in them, rather than the tradiional 8-bit ASCII characters. This means that there is no easy method of creating a String (or a Character) from just a single 8-bit number. Java expects an array of such bytes.
For most regular 8-bit character codes this should not be a problem, though; you can just create a single-item array:

Does that make any sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!