Current Request Dispatcher

Hi all!

I've a question about the request dispatcher. Let me describe the situation.

I've a jsp that with a specific custom tag dispatches (using "include") to a servlet that generates an xhtml document . This document is inserted in the positing where custom tag was used (like tiles).

I need 2 or 3 different servlet (they are quite simple) to do the job and I was thinking about using the same servlet.

I CANNOT use a parameter in the query string because this component must replace an existing one and I cannot go over many hunders of file to change links, ecc...

I thought about using one servlet (for exmaple ExeServlet) mapped to different url (e.g. /exe /route /process) names but I cannot read back from the request (after the inclusion from requestdispatcher) what servlet name was used! It always the jsp file name.

From the doEndTag of my tag I have:

.....

pageContext.include(processor);

where processor is a string mapped to a tag attribute (e.g. processor="/exe")

and in my doGet(..) I cannot know if the serlvet was included using /exe or /route or /process url! I could have used that name as a "switch" for my action...

None of the request.getXXX sends me back /exe (or /process or /whatever)

Is there a specific method to know this? I'm using Tomcat 6.

Hope I was clear enough!

Many thanx to everyone.

Bye!

[1426 byte] By [xtc77a] at [2007-11-27 9:33:26]
# 1

> I've a jsp that with a specific custom tag dispatches

> (using "include") to a servlet that generates an

> xhtml document .

I don't think this is the proper way to understand the RequestDispatcher. The RequestDispatcher functions differently than a server side include because it can redirect the request entirely to a different resource on the server.

> This document is inserted in the

> positing where custom tag was used (like tiles).

Yes this is the operation of an include tag.

> I need 2 or 3 different servlet (they are quite

> simple) to do the job and I was thinking about using

> the same servlet.

Using 2 or 3 servlets in either an include operation or through the use of a RequestDispatcher is something I've never done. Generally the include tag points to a single resource, as does the RequestDispatcher. In any case this is a design/development issue and one that you may need to sort out on your own unless you are prepared to post the code.

> I CANNOT use a parameter in the query string because

> this component must replace an existing one and I

> cannot go over many hunders of file to change links,

> ecc...

No idea what you mean here.

I suggest you review the differences between the include action and the include directive

<jsp:include page="/path/file" />

<%@ include file="relative url" %>

and contrast these functions with that of the RequestDispatcher object and then if you need additional help, return and post a general discription of what it is you are trying to do.

nantucketa at 2007-7-12 22:55:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Well, thank you for your reply!

Yes, this is a design issues, but it's not my fault. I must migrate a portal engine, not developed by myself from asp to java. This portal uses a very strange mode to generate pages, by combining xml transformed with xslt pieces in a "template" page. The problem is that there is a HUGE number of files for page generation and these MUST NOT be touched.

So I have to use a similiar system.

The template page is now a jsp with a special custom tag developed by myself that act like a struts "tile" template. There shuold be 2 servlet one that receive a "call" from the browser, this sevlet do something with the parameters than pass the control (using a forward) to a jsp (the famouse template page). Each "tile" tag in that page calls (using an include dispatching, not @include) to another servlet that generate the xml/xslt and output the html to the place where the tag was used.

Well my idea, if possible, is to use only one servlet to do the whole job. when a doPost o doGet method is called I have to know if the request was activated from a "forward" or from an "include" from another resource. If it's included, I should generate xml/xslt, if it's forwarded i should send control to the template.jsp. That's all.

I've found, by reading specs, of some request attributes like javax.servlet.include.servlet_path (and others) and javax.servlet.forward.servlet_path (and others, the same as include).

That's GOOD, now I can know about forward or include but my tomcat 6 set both of them. Well, this request is forwarded or included? I think that if include-attributes are present they have some sort of "priority" over the forward ones.

Hope I was much clear now, english is not my own language, and yes, I know the difference between the include directives and action. I've been coding with servlet since 1999, the early stages of this technology and it's the first time I need such a strange thing...I would done this using a completely different architecture...but it's not mine.

Finally, I can always resort to the fall back method of aving 2 different servlet...it's just to reduce code here and there. This portal engine is a real mess.

Many thanx in advance!

xtc77a at 2007-7-12 22:55:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> Well my idea, if possible, is to use only one servlet

> to do the whole job. when a doPost o doGet method is

> called I have to know if the request was activated

> from a "forward" or from an "include" from another

> resource. If it's included, I should generate

> xml/xslt, if it's forwarded i should send control to

> the template.jsp. That's all.

You could set an attribute value on the request object at the time of the forward.request.setAttribute( "doforward", Boolean.TRUE );

Then check for the presence of this attribute in the servlet.

nantucketa at 2007-7-12 22:55:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Yes, this is the workaround I'm using rightnow... but I would know if there is a "standard" method for this...

There are thoose request attributes defined by the specs.... but the include attributes are available from specs 2.4 and the forward one only from 2.5.

Hope to find a solution... ;)

Anyway thank you for your reply!

xtc77a at 2007-7-12 22:55:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> > I've a jsp that with a specific custom tag

> dispatches

> > (using "include") to a servlet that generates an

> > xhtml document .

>

> I don't think this is the proper way to understand

> the RequestDispatcher. The RequestDispatcher

> functions differently than a server side include

> because it can redirect the request entirely to a

> different resource on the server.

>

Actually I've conveyed something incorrect here. I was thinking specifically about the "forward" method of the RequestDispatcher and failed to recall that the "include" method is also one of the RequestDispatcher object. So my posting was incorrect in that sense. I should have contrasted forward with include but I should note that both are the operation of the RequestDispatcher.

nantucketa at 2007-7-12 22:55:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...