You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ha...@informatiefabriek.nl on 2003/07/07 15:34:37 UTC

include javascript (urgent)

Hi all,

I'm using the Struts framework for my web application.
Unfortunatly I have to include some java-script from an other webserver 
(Lotus Domino).

I have stored the url for the include in a Bean called: URLBean:

package ordermanager.urlbean;
public class URLBean {
        private String scriptFile;
        public String getScriptFile() {
                return scriptFile;
        }
        public void setScriptFile(String string) {
                scriptFile = string;
        }
}

In my first Action I create the URLBean. And I add it to the session 
object using the following code:

URLBean urlBean = new URLBean();
urlBean.setScriptFile(properties.getProperty("script.include"));
request.getSession().setAttribute("urls", urlBean);

Then In my JSP I tried to do this:

<logic:present name="urls">
        <jsp:useBean id="urls" scope="session" class="ordermanager.urlbean
.URLBean" />
        ScriptFile: <bean:write name="urls" property="scriptFile"/> <br/>
</logic:present>

This code works... But I want to use this url in a <script> tag like this:

<script src="<%= urls.getScriptFile() %>"></script>

But when I try this I get a comiple error. Jasper complains that the urls 
object cannot be found.
What am I doing wrong. And what should I do to correct it?

Thanks,

Harm de Laat
Informatiefabriek


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: include javascript (urgent)

Posted by Alex Shneyderman <al...@law.columbia.edu>.

> -----Original Message-----
> From: harm@informatiefabriek.nl [mailto:harm@informatiefabriek.nl]
> Sent: Monday, July 07, 2003 9:35 AM
> To: struts-user@jakarta.apache.org
> Subject: include javascript (urgent)
> 
> Hi all,
> 
> I'm using the Struts framework for my web application.
> Unfortunatly I have to include some java-script from an other
webserver
> (Lotus Domino).
> 
> I have stored the url for the include in a Bean called: URLBean:
> 
> package ordermanager.urlbean;
> public class URLBean {
>         private String scriptFile;
>         public String getScriptFile() {
>                 return scriptFile;
>         }
>         public void setScriptFile(String string) {
>                 scriptFile = string;
>         }
> }
> 
> In my first Action I create the URLBean. And I add it to the session
> object using the following code:
> 
> URLBean urlBean = new URLBean();
> urlBean.setScriptFile(properties.getProperty("script.include"));
> request.getSession().setAttribute("urls", urlBean);
> 
> Then In my JSP I tried to do this:
> 
> <logic:present name="urls">
>         <jsp:useBean id="urls" scope="session"
class="ordermanager.urlbean
> .URLBean" />
>         ScriptFile: <bean:write name="urls" property="scriptFile"/>
<br/>
> </logic:present>
> 
> This code works... But I want to use this url in a <script> tag like
this:
> 
> <script src="<%= urls.getScriptFile() %>"></script>

This is impossible with the way you do it. You want to use it as a
context independent variable and yet you attach your bean to the session
context. You will have to declare and initialize the urls variable
somewhere in your script. Otherwise you can't get to it. So something
like this will work:

URLBean urls = (URLBean) request.getSession ().getAttribute ("urls");

But then again is it shorter or better than what you have already. I am
not so sure.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org