• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAVASCRIPT functions and not .JAVA  RSS feed

 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a small sample of a JSP that I would like to get working. It does not do anything special but the concept I want to get working. What am I doing wrong.
Thanks,
"contents of .JSP"

<SCRIPT LANGUAGE=javascript RUNAT="Server">
function String funcTest( String value)
{
return value;
}
</SCRIPT>
<HTML>
<BODY>
<%= funcTest( "Test text") %>
</BODY>
</HTML>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not very familiar with server-side JavaScript, so I don't know exactly how to solve your problem, but I do know that you wouldn't use the JSP notation to invoke the JavaScript function.
So, why the server-side JavaScript?
bear
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to be able to reuse code through a functional process without having to do a cut & paste and not have to create .JAVA code and be needing to recompile.
ASP does what I am trying to do very well. Unfortunately or fortunately I need to write in JSP.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run server-side Javascript using the Bean Scripting Framework.
BSF web page (one of many)
Do a search at yahoo for lots more.
Its a bit of a pain to set up but lets you run Javascript scripts from a servlet container. Cocoon uses it for instance.
As you say, you don't have to recompile so it makes for a rapid development cycle.
Bill
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer but beans are not the answer I was looking for. I did not wnat to create any Java code. It appears that beans & servlets are the only answer here. Thanks anyway.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite sure I understand your issue but here goes ... You state:
I want to be able to reuse code through a functional process without having to do a cut & paste and not have to create .JAVA code and be needing to recompile.
ASP does what I am trying to do very well. Unfortunately or fortunately I need to write in JSP.

One statment you say you do not want to use .JAVA and then you say you need to write it in JSP. Well java is JSP. And yes, you can do what your asking in ASP, Javascript as well as JSP.

is similar to ...

If I am not mistaken both function/methods can be
invoked the same way ...

Asp has a similar syntax. I admit this is a crude
example of JSP, but I hope this will shed some light on your situation.
craig.
 
Ramesh Lakshmanan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kelly Harris ,
I think you are little bit confused with Calling the JavaScript functions inside the JSP .
it's different .
Either you will have to write the JavaScript function as JSP method,
Here u go,
<!-
public String getName(String name)
{
return name;
}
%>
<%
out.println(getName("Ramesh"));
%>
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ramesh and CJ. Your examples are similar to mine but yet mine does not work. I guess the difference is I need to put public instead of function? I believe I tried it but I will try again. Maybe it is a problem with Tomcat?
 
Ramesh Lakshmanan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kelly Harris,
Just like that we can tell that it'z problem with TOMCAT.Remember around thousands of developers worked to bring that prestigous server.
I am damp sure that you might have to look into the code.
thx
Ramesh
 
Benjamin Arciszewski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why you need to put the JavaScript in a .JSP here. It appears that you are trying to do a SSI? Unfortunately, all my Javascript experience is on the client side. I've modified the JavaScript above so that it would work on the client side, maybe it will help:

JavaScript is not a strongly typed language, so it you do not have to declare the type of the argument you are passing in. In addition, you do not have to declare a return type to the function, either.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!