Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't use javascript with .jsp

Status
Not open for further replies.

aob

Programmer
Jun 30, 2001
10
MX
When I try to use any javascript on a .jsp page I receive an error and can get my script to work.

Any comments?

alejandro
 
What are you trying to do, use JavaScript as your server-side scripting logic, or include JavaScript as part of the server response that renders in the browser?

In the former case, You have to include a directive at the top of your document something like this:
Code:
<%@language=&quot;javascript&quot; %>
Otherwise the interpreter assumes you are using VBScript.

Petey
 
Petey:

I have a .jsp page running fine and I want to set a link to open a new browser window (those without all the bars off). My problem is that when I insert the code to open that window (or any other javascript code) the script doesn't work and throws that dreadful error message. Everything else is ok but the javascript.

I guess I want to include javascript as part of the page that renders the browser, I'm lost .

I'll try the solution you provided me.
Any other ideas?

Please help.

Alejandro
 
Petey:

Me again.

I tried at the top <%@script language=&quot;JavaScript&quot; %>
but the server answers with an internal server error 500, Invalid Directive.

Completely lost

Alejandro
 
That's because you got it backwards. Petey was giving you the syntax to parse Javscript on the server, which would have nothing to do with opening new browser windows, or any other client-side Javscript functions. You need the second option: &quot;JavaScript as part of the server response that renders in the browser&quot;.

In other words, this should have nothing to do with JSP at all, but should just be flat text passed to the browser, just like HTML, so the browser can parse it.

I'm not familiar with JSP, but I imagine it has a print() command, or a write() command, like any other scripting language:

print(&quot;<script language=\&quot;Javascript\&quot;>window.open(\&quot;name\&quot;, \&quot;filename\&quot;,\&quot;window_options\&quot;)</script>&quot;);

Would be the sort of syntax you are looking for, where your output is just a simple quoted string, with internal quotes escaped.
 
I know this thread was started about eight hundred years ago, but I have run into a problem which may be the true problem aob was talking about.

In a .jsp page, text not between <% and %> is simply sent to the browser as text, allowing the browser to figure out what to do with it.

One would expect therefore that you could simply write your client-side JavaScript into your JSP and have it passed to the browser to be executed.

However I ran into a problem with this. I had a script tag in a JSP (not between any <% %> tags) and the page would generate a compilation error.

Investigation revealed that if I printed the script tag explicitly...
Code:
<% out.print(&quot;<script language=\&quot;javascript\&quot;>&quot;; %>
...or broke the script tag apart...
Code:
<scr<% %>ipt language=&quot;javascript&quot;>
...the page would compile and run as expected.

Can anybody shed light on this odd behavior? (probably should post this as new thread in a different forum)

-Petey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top