• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAVASCRIPT functions and not .JAVA

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic