Hi Martin,

The script tag here is not meant to be a Javascript, I suppose. Actually it 
appears after the </html> close tag!

The code I posted was an example from Jason Hunter's Java Servlet 
Programming.
Everything works fine except when the variable 'name' is 'null' and supposed 
to output DEFAULT_NAME="world".

Here is the whole code once again :

<HTML>
<HEAD><TITLE>Hello1</TITLE>
<BODY>
<H1>
Hello, <%= getName(request) %>
</H1>  <br>
</BODY>
</HTML>

<SCRIPT RUNAT="server">
<%! private static final String DEFAULT_NAME = "World"; %>

 <%!

  private String getName(HttpServletRequest req) {
  String name = req.getParameter("name");
  if (name==null)
    return DEFAULT_NAME;
  else
    return name;
}
%>
</SCRIPT>

Any further suggestion(s)  ?

-Bob


In a message dated 14.02.2003 04:52:04 Westeuropäische Normalzeit, 
[EMAIL PROTECTED] writes:

> Make SURE all your javascript is inside the HTML Header
> here is an example:
> 
> <head>
> <%@ Language = JavaScript %>
> <script type="text/javascript">
> document.writeln("the Request parameter is "+getName(request));
> </script>
> </head>
> Regards,
> Martin
> 
> ----- Original Message -----
> From: "Peter Kleczka" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, February 13, 2003 11:28 PM
> Subject: Re: Strange Jsp Behaviour
> 
> 
> >Here's a guess. Close off the tag for the static string. For example:
> ><%! private static final String DEFAULT_NAME = "World"; %>
> >
> >Then put the rest of your code in
> ><%
> >  // the rest of your code
> >%>
> >
> >
> >
> >--- Bob Prah <[EMAIL PROTECTED]> wrote:
> >>I can't get the following code to display the string variable
> "DEFAULT_NAME"
> >>when variable "name" is null or empty. This appears unusual :
> >>[
> >>
> >>
> >><HEAD><TITLE>Hello1</TITLE></HEAD>
> >>
> >>
> >>Hello, <%= getName(request) %>
> >>
> >>
> >>
> >>
> >><SCRIPT RUNAT="server">
> >><%! private static final String DEFAULT_NAME = "World";
> >>
> >>  private String getName(HttpServletRequest req) {
> >>  String name = req.getParameter("name");
> >>  if (name==null)
> >>   return DEFAULT_NAME;
> >>  else
> >>   return name;
> >>}
> >>%>
> >></SCRIPT>
> >>
> >>]
> >>
> >>Any suggestion will be much appreciated.
> >>
> >>-Bob
> >>
> >>
> 

==========================================================================To 
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to