On Thu, 29 Aug 2002, Edward King wrote: > <% > String[] msg=new String[2]; > msg[0]="Hello"; > msg[1]="world"; > %> > > Then I transfer msg into Javascript,like follows: > > <td width="159px" onclick="display(<%=msg[0]%>)"><B>Click Here</B></td> > > I found it can't work at! Why? I have thought of it for a long > time,but I still don't know to do it! How to correct this JSP file?
Your JSP page simply outputs text that web browsers interpret. There is no formal conduit for communicating strongly typed information from JSP to JavaScript; everything is mediated by the text that the server sends back. You can't simply pass parameters as with a Java method call. Thus, when you sent a Java String to JavaScript, you need to insert quotation marks, for the browser will need them to interpret the JavaScript correctly. That is, you need to construct the text correctly, and in this case, quotation marks are required. You therefore want to write display('<%= msg[0] %>') As a side note, it also looks like you mean more to use an <a> than a <td> element . . . -- Shawn Bayern "JSTL in Action" http://www.jstlbook.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com