[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: struts help
From:       "Craig R. McClanahan" <Craig.McClanahan () eng ! sun ! com>
Date:       2000-07-19 20:01:31
[Download RAW message or body]

Chris Miller wrote:

> Just a quick note to say that Craig's code is not quite right - instead of
> "getServletContext()", you need to use "config.getServletContext()".
>
> (Hey, I'm new to all this and it took me a bit to figure this out ;-).
>

Chris is right of course -- servlets that inherit from GenericServlet provide
a getServletContext() method for you, but the Java class that a JSP page
generates does not subclass this class -- it only implements the Servlet
interface which has getServletConfig().

I guess you can tell how many times I actually embed Java code in my JSP
pages, if I thought that this would work :-).

Craig


>
> ----- Original Message -----
> From: "Craig R. McClanahan" <Craig.McClanahan@eng.sun.com>
> To: <struts-user@jakarta.apache.org>
> Sent: Tuesday, July 11, 2000 5:16 PM
> Subject: Re: struts help
>
> >
> >
> > Bauert Daniel wrote:
> >
> > > Dear Sir or Madam
> > >
> > > I'm working with your struts framework and would like to do the
> following...
> > >
> > > <struts:link href="http://mylink/myHtmlPage.do?action=<struts:message
> > > key="MyKey" />" target="_top">
> > >
> >
> > Unfortunately, this is not valid JSP syntax -- you cannot nest a JSP tag
> inside
> > another JSP tag.  If a tag allows runtime expressions, they have to be
> done with
> > scriptlets.
> >
> > In my programs that do the kind of thing you are doing above, I tend to
> use the
> > canonical translation of the action ("Create" or "Edit" in the example
> > application, for instance), and translate it in the destination page or
> Action
> > class if I will need to display it to the user.  At the moment, if you
> really
> > want to do it as you are generating the link, you will need to use a
> scriptlet
> > -- something along these lines:
> >
> >     <%
> >         MessageResources resources = (MessageResources)
> >
> getServletContext().getAttribute("org.apache.struts.action.MESSAGE");
> >         String uri = "http://mylink/myHtmlPage.do?action=" +
> >           resources.getMessage("MyKey");
> >     %>
> >
> >     <struts:link href="<%= uri %>" target="_top">...</struts:link>
> >
> > >
> > > The error message is that MyKey has no value. Could you tell me what I
> must
> > > do to correct this error?
> > >
> > > Thanks four your help.
> > >
> > > Yours sincerely
> > >
> > > Daniel Bauert
> >
> > Craig
> >
> >
> >

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic