aspose file tools*
The moose likes Servlets and the fly likes Pass values from Servlet to Custom Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pass values from Servlet to Custom Tag" Watch "Pass values from Servlet to Custom Tag" New topic
Author

Pass values from Servlet to Custom Tag

Heath Williams
Greenhorn

Joined: Jan 22, 2004
Posts: 6
Is it possible, on serverside, to get a "tag" object, set some values to it, then pass that to the jsp and display the value. I want to do this without scriplets in the jsp.

For example on the server get the tag object:


On the jsp have a tag like this:


And when the jsp compiles have it look like this:


And Display:
Test

Thanks for your help.

Heath
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

No, it is not possible. You'll need to back up a bit and explain what it is you are actually trying to accomplish. I'm sure that there is a supported way to implement it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

And "Heath W",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
Heath Williams
Greenhorn

Joined: Jan 22, 2004
Posts: 6
Thanks for the reply.

I am developing a web application for a company and the "java base" code will be used over and over for other applications for this company. My thought was to create a custom tag library and in the class model create an "object" for each of the custom tags. So when other programmers wanted create a page with dynamic content they can use the custom tag jsp side and custom tag "object" server side.

See to me it would be easier and faster to program:
JSP:

JAVA:


Rather than a bean that sets and gets everything out of the result set. Put the bean in the session then use a scriplet to get it out of the bean on the jsp.

I figure I could do all the session manipulation in the parent class of the "component" that gets the custom tag object. All the programmer has to do is get the tag object set it.

Let me know if my thought process is too confusing.

[ April 04, 2005: Message edited by: Heath W. ]
[ April 04, 2005: Message edited by: Heath Williams ]
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
Seems like from the JSP page you are trying to get an attribute that was set in the servlet. So, why don't you put it in request object from the servlet and retrieve it from the tag handler like this:


Hope I am talking about what you asked.

Regards,
[ April 04, 2005: Message edited by: Heonkoo Lee ]
Heath Williams
Greenhorn

Joined: Jan 22, 2004
Posts: 6
Thanks for the reply Heonkoo.
Genius. I didn't realize you could get the request inside a tag handler. But when I looked in the java doc I found this and it looks like this should work:



I haven't tried it yet but does it look right to you?

Thanks for your help.

Heath
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Yes, the pageContext field gives you complete access to the environment of the page in which the tag appears.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass values from Servlet to Custom Tag