You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Johan Compagner <jc...@j-com.nl> on 2001/01/03 17:17:04 UTC

I want the reques t URL.

Hi,

If i click on a link that opens another page. And i that page i want
a link that wants the url that constructed that page.

for example:

The link i clicked on:
/maintenance.do?thema_key=pension

that shows the jsp page: maintenace.jsp

in that page i have my own TAG that extracts the info of that page
like this:
	java.util.Enumeration enum = request.getParameterNames();
	StringBuffer sb = new StringBuffer();
	while(enum.hasMoreElements())
	{
		String sKey = (String)enum.nextElement();
		sb.append(sKey);
		sb.append("=");
		sb.append(request.getParameter(sKey));
		if(enum.hasMoreElements()) sb.append("&");
	}
	String sHref = request.getServletPath();
	if(sb.length() > 0)
	{
		sHref += "?" + sb.toString();
	}

But the link i get is:
/maintenance.jsp?thema_key=pension

Not the .do version.

I know why this happens because the action that is triggerd
with maintenace.do 'forwards' the request to the maintenace.jsp page.
But i want the 'REAL' link that generates that page.
How do i get that link/URI?
Is there a forwards stack or something?

If i dig through the request i see that the headers contains:
Referer: http://localhost:8080/postbank/maintenance.do?thema_key=pension

Is this the only reference to the request that really makes the page?
And is it always there?

I need this because i want the user to give the abillity to change the
locale
on 'every' page he wants so i have a Action that changes the locale of the
user
and then i want it to return to the page it came from (with the different
language)

johan






Re: I want the reques t URL.

Posted by Ted Husted <ne...@husted.com>.
On 1/3/2001 at 5:17 PM Johan Compagner wrote:
> If i dig through the request i see that the headers contains:
Referer:
http://localhost:8080/postbank/maintenance.do?thema_key=pension
Is this the only reference to the request that really makes the page?
And is it always there?

It * should * be present, as it's part of the HTTP specification.
Though, if they came in from a bookmark or something, the referrer page
might not be part of your application (unless some other logic is at
play). Also not sure if your browser's home page ends up with a
Referrer or not. 

> I need this because i want the user to give the abillity to change
the locale on 'every' page he wants so i have a Action that changes the
locale of the user and then i want it to return to the page it came
from (with the different language)

I'd consider a tag or scriplet that created your own version of the
referrer with something like (untested code)

page.setAttribute("referrer",session.getAttribute("referrer")); //
cache last referrer in page context
session.setAttribute("referrer",request.getServletPath()); // set new
refererrer

This would also be useful if you wanted to bounce someone to a login
page, and then back to where they were (if where they were is part of
your application!). 

(Historical note: the word "referer" in the HTTP header was misspelled,
and never changed!) 

HTH. -Ted.

*********** REPLY SEPARATOR  ***********

Hi,

If i click on a link that opens another page. And i that page i want
a link that wants the url that constructed that page.

for example:

The link i clicked on:
/maintenance.do?thema_key=pension

that shows the jsp page: maintenace.jsp

in that page i have my own TAG that extracts the info of that page
like this:
	java.util.Enumeration enum = request.getParameterNames();
	StringBuffer sb = new StringBuffer();
	while(enum.hasMoreElements())
	{
		String sKey = (String)enum.nextElement();
		sb.append(sKey);
		sb.append("=");
		sb.append(request.getParameter(sKey));
		if(enum.hasMoreElements()) sb.append("&");
	}
	String sHref = request.getServletPath();
	if(sb.length() > 0)
	{
		sHref += "?" + sb.toString();
	}

But the link i get is:
/maintenance.jsp?thema_key=pension

Not the .do version.

I know why this happens because the action that is triggerd
with maintenace.do 'forwards' the request to the maintenace.jsp page.
But i want the 'REAL' link that generates that page.
How do i get that link/URI?
Is there a forwards stack or something?

I need this because i want the user to give the abillity to change the
locale
on 'every' page he wants so i have a Action that changes the locale of
the
user
and then i want it to return to the page it came from (with the
different
language)

johan




Re: I want the reques t URL.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Johan Compagner wrote:

>
> by the way when i want default object(s) be initalized for every session object
> that is created. What is the best way for doing that?
> Something like the Locale object problem (not initialized when you don't use the <form:html> tag.
> I want a Customer object for every session object i make, without checking this one every
> page i created (when users bookmark it)
>

In a servlet 2.3 environment (like Tomcat 4.0), you would be able to do this by using the new
"application event listener" feature.  One of the listeners you can define hears about all new
session creations (no matter where they came from), so you could use it to populate your default
objects.

In a 2.2 environment, however, I can't think of a solution any better than what we did with locales -
put logic in both the controller servlet *and* a tag that is used on every page.  If you decide to go
the latter route, one thing you might think about is subclassing an existing tag class (like the
<form:html> tag) that is usually used on every page anyway, and have it do the extra work for you.

>
> johan

Craig



Re: I want the reques t URL.

Posted by Johan Compagner <jc...@j-com.nl>.
> I do not think that the "Referer" header will give you what you want, either --
> that comes only from the browser, which doesn't know anything about the server
> side forwarding.

Yes i came a cross this already

 
> I would suggest subclassing ActionServlet and making sure you create a
> request-scope attribute with a well-known name, containing the value returned by
> request.getServletPath() at that point.  Then, in your JSP page, you can refer
> to that request attribute to get the value you need.

I will do that thx!

by the way when i want default object(s) be initalized for every session object
that is created. What is the best way for doing that?
Something like the Locale object problem (not initialized when you don't use the <form:html> tag.
I want a Customer object for every session object i make, without checking this one every
page i created (when users bookmark it)

johan



Re: I want the reques t URL.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Johan Compagner wrote:

> Hi,
>
> If i click on a link that opens another page. And i that page i want
> a link that wants the url that constructed that page.
>
> for example:
>
> The link i clicked on:
> /maintenance.do?thema_key=pension
>
> that shows the jsp page: maintenace.jsp
>
> in that page i have my own TAG that extracts the info of that page
> like this:
>         java.util.Enumeration enum = request.getParameterNames();
>         StringBuffer sb = new StringBuffer();
>         while(enum.hasMoreElements())
>         {
>                 String sKey = (String)enum.nextElement();
>                 sb.append(sKey);
>                 sb.append("=");
>                 sb.append(request.getParameter(sKey));
>                 if(enum.hasMoreElements()) sb.append("&");
>         }
>         String sHref = request.getServletPath();
>         if(sb.length() > 0)
>         {
>                 sHref += "?" + sb.toString();
>         }
>
> But the link i get is:
> /maintenance.jsp?thema_key=pension
>
> Not the .do version.
>

When you do a forward, as you have seen, all the request properties get
converted to reflect the page you are forwarding to, not the "page" (i.e. the
action's URI) that you came from.  So the servlet and JSP APIs are not going to
help here.

I do not think that the "Referer" header will give you what you want, either --
that comes only from the browser, which doesn't know anything about the server
side forwarding.

I would suggest subclassing ActionServlet and making sure you create a
request-scope attribute with a well-known name, containing the value returned by
request.getServletPath() at that point.  Then, in your JSP page, you can refer
to that request attribute to get the value you need.


>
> johan

Craig