• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Dynamically assign an included bean property

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
Is there any reason why this doesn't work?
<jsp:include page="../includes/adminheader.jsp">
<jsp aram name="path" value="<% out.write(sPath); %>"/>
</jsp:include>
I'm trying to dynamically assign the value of the 'path' parameter. Basically, the value of sPath doesn't come through.
I'm not sure if this is the right way of going about it, and any recommendations are greatly appreciated.
Cheers,
Steve
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like you are getting a little confused between the source code of the JSP (things like <jsp:include> tags) and the generated HTML (things like HTML, plain text, etc.).
What you seem to be trying to do is modify the source code of the JSP at the time it is compiled. To a certain degree this is possible. However, you can't do it using out.write() which is only executed when the JSP has been compiled and is running on the deployed server.
The trick is that JSP often allows you to use the superficially similar <%= expression %> syntax for the kind of source-level change you need. Try the follwoing:

and see if it works.
Of course, if you have JSP 2 (found in Tomcat 5 or Resin 3, for example), you should probably be using the new "EL" syntax instead:

[ January 08, 2004: Message edited by: Frank Carver ]
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Frank,
I tried the example you gave and it didn't work.
Maybe I should explain a bit better what I'm trying to do.
Basically, the path variable is used to pass the current location into the page header (i.e. sPath = "Books > Technical") which is then output in the header text. I'm basically trying to give the header some text before it loads, but the text is not something that can be hard-coded on the page - it very much depends on the way the page is called.
i.e. this works:
<jsp:include page="../includes/adminheader.jsp">
<jsp aram name="path" value="Books > Technical" />
</jsp:include>
but isn't practical.
In ASP you can simply share variables between included pages - I was using the parameter feature to try to mimic this:
example page:
<%
sPath = "Books > Technical"
%>
<#include admin header page here>
...
example admin header:
<html>
<body>
<%
out.write(sPath)
%>
...
Basically, the sPath variable is shared as if the admin header and example page were in the same application scope.
I hope this makes a bit more sense.
Thanks a lot for your help.
Cheers,
Steve
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aha.
There is a much simpler way to do what you want. A JSP container provides four "contexts", which can be used to pass any value between servlets and JSPs.
  • "application" context is a single context available to all servlets and JSPs in an application.
  • "session" context is a seoarate context for each session (sequence of calls from the same client),
  • "request" context is a context which exists for the duration of the procesing a single HTTP request.
  • "page" context is a context whch exists only for the duration of the processing of a single JSP page.


  • In your case, the "request" context seems most appropriate, as it will be available to both your "calling" and "included" JSPs when they are both collaborating on responding to a single request.
    In your "calling" JSP, put something like:

    In your "included" JSP put something like:

    If you can do this "under the hood" in ASP, I guess that the ASP server probably places all values in somethlng akin to the "request" context by default.
    Has that helped?
     
    Steve Wood
    Ranch Hand
    Posts: 137
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    That's a much better way of doing it. Thanks a lot for your help - I think I was getting a bit bogged down with a certain line of thinking.
    Thanks again,
    Steve
     
    All of the following truths are shameless lies. But what about this tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic