Thanks a lot
Bhavesh, August 06, 2002 - 8:59 pm UTC
Hi Tom,
As usual, you are the best. I think I have started becoming lazy in cracking the nuts as most of the problems are already there on your forum answered by I believe the best. Thanks a million.
Regards
Bhavesh
redirecting URL
mo, July 02, 2003 - 12:24 pm UTC
TOm:
I am using this owa_util.redirect_url in a "save_shipment" procedure to display the save results in another page but all I get a the name of redirect in the save proceduee. It does not change the url and run the other one to display the results. do you know what is happening.
--Procedure Save_shipment
.....
owa_util.redirect_url('save_new_shipment_display?i_shipment_id='||v_shipment_id||'&i_user_id='||i_user_id);
---
This is what I get in the results page which is still pointing to the save_shipment link.
Location: save_new_shipment_display?i_shipment_id=2183&i_user_id=john
July 02, 2003 - 2:06 pm UTC
you have other htp.p calls before the owa_util.redirect_url.
that must be the first owa type call (htp, etc).
The location tag must be in the header.
redirect
mo, July 02, 2003 - 5:22 pm UTC
Tom:
yes i do have some htp statements for <html> and Header and son on but i did not have the redirect in the <head> if that what u mean.
I also used the other code you have instead and it worked fine.
htp.p( '<HTML><HEAD>
<META HTTP-EQUIV="Refresh"
CONTENT="0;URL=' || p_url || '"></HEAD><body>
<a href="' || p_url || '">Redirecting...</a>
</body></html>' );
Is there any difference?
July 03, 2003 - 8:42 am UTC
yes there is differences.
all you needed to do was use the owa-util call and NO OTHER HTP calls (they are meaningless no -- you do not want the user to see that page anyway -- if you use owa_util.redirect_url and htp, I would ask you to ask yourself "why")
redirect
mo, July 03, 2003 - 6:51 pm UTC
Tom:
Thanks I will change it to use the owa_util.redirect but:
1. What is the disadvantage of using the <META> tag like above instead of owa_util.redirect.
2. When do you use this "utl_http.request_pieces". I am confused on what is the use of each.
Thank you,
July 03, 2003 - 8:20 pm UTC
1) do you like having your user stare for a second or two at a screen that says "hold on, i'm doing what you asked" -- or would it be nice for it just to look seamless.
the meta redirect "flashes" the screen, doesn't look nice.
2) when the page exceeds the size of a plsql variable pops into mind. if you try to get a 500k page with utl_http, you'll find you better get it by piece since 32k is the biggest variable.
redirection
mo, August 24, 2005 - 6:16 pm UTC
Tom:
1. The owa_util.redirect submits a "get" request showing the parameters in the URL. Is there a way to do a "post" request instead.
2. I did not notice a difference btween using the owa_util.redirect_url and <META> tag. Where do you see this flash on the screen.
Thanks,
August 25, 2005 - 3:27 am UTC
1) java script could do lots of things
2) you will on a slow enough network.
post with owa_util.redirect_url
Jon Roberts, September 01, 2005 - 11:53 am UTC
Mo asked about using a post with owa_util.redirect_url and you said it could be done with javascript which is true. I am guessing you mean something like this:
Page1.html
<a href="pls/dad/pr_page_2>click me</a>
--using Discoverer as the example
create or replace procedure pr_page_2 is
v_url varchar2(2000);
begin
v_url := '</code>
http://disco10g.humana.com/discoverer/viewer'; <code>
htp.p('
<html>
<body onLoad="document.LoginForm.submit();">
<form action="' || v_url || '" method="post" name="LoginForm">
<input type="hidden" name="us" value="scott">
<input type="hidden" name="pw" value="tiger">
<input type="hidden" name="db" value="orcl">
</form>
</body>
</html>');
exception
when others then
htp.p('<pre>' || sqlerrm || '</pre>');
end;
So with Java Script, onLoad will submit the Form as a post and it hides the parameters in the URL. However, the stuff I'm trying to hide is still visible in the HTML.
It seems to me that owa_util.redirect_url should have a parameter for POST so that I can post directly to a redirected URL. I can probably write this with Java or Perl or whatever but it would be nice to do this with mod_plsql. Your thoughts?
September 01, 2005 - 3:55 pm UTC
owa_util.redirect_url just pumps out location tag.
location does post?
ops$tkyte-ORA10G> exec owa_util.redirect_url( 'xxx' );
PL/SQL procedure successfully completed.
ops$tkyte-ORA10G> exec owa_util.showpage;
Location: xxx
Content-length: 0
PL/SQL procedure successfully completed.
redirection
mo, September 08, 2005 - 1:26 pm UTC
September 08, 2005 - 4:27 pm UTC
don't know, don't know your inputs for everything.
A reader, September 09, 2005 - 9:29 am UTC
htf.escape_sc should not be used for urls. It htmlø-encodes and you shouldn't write html in the http header (where the location line are located). Maybe you can use this function:
create or replace function urlencode( p_str in varchar2 ) return varchar2 as
l_tmp varchar2(12000);
l_len number default length(p_str);
l_char char(1);
begin
if ( p_str is null ) then
return null;
end if;
l_tmp := replace(p_str, '%', '%' || to_char(ascii('%'), 'fm0X'));
for i in 1 .. l_len loop
l_char := substr(p_str,i,1);
if not ( l_char between 'a' and 'z' or l_char between 'A' and 'Z'
or l_char between '0' and '9' or l_char in ('%', '_', ' ') ) then
l_tmp := replace(l_tmp, l_char, '%' || to_char(ascii(l_char), 'fm0X'));
end if;
end loop;
return replace(l_tmp, ' ', '+');
end;
/
It is basicly Toms function, but a little more defencive (ei. a l_good instead of a l_bad) and hopefully faster en the common case, from
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:10444643777538 <code>
You could also use the utl_url.escape function but it omits some characters compared to php and asp.
redirection
mo, September 09, 2005 - 2:49 pm UTC
yes, the urlencode solved the problem
thanks a lot
Tip on redirecting after login
Ben, February 28, 2006 - 5:37 pm UTC
I spent a few hours frustrated with trying to set up cookie-based authentication with PL/SQL Web Toolkit, so I'd like to offer this tip.
I wanted to redirect the user to the original URL after they were redirected to my login form. The problem is that after checking that the username/password was valid, I set a cookie using the following code:
OWA_UTIL.mime_header('text/html',false);
OWA_COOKID.send(l_cookie_label,l_cookie_value);
OWA_UTIL.http_header_close;
This is the most commonly given example of how to set a cookie. The problem is that if you then call OWA_UTIL.redirect_url you end up with a page that just says "Location: <l_my_url>". The redirect doesn't work.
When you call OWA_UTIL.redirect_url, you're not supposed to have any other HTP calls before that. So it seemed there was no other possibility other than to dump the user on a static page after login.
I really didn't like this, since I'd like to take users back to the page they wanted to see, and I want every page to just check the cookie to determine if the user is authenticated. After a log of fruitless searching, I started trying a few variations. The following is what worked:
OWA_UTIL.mime_header('text/html',false);
OWA_COOKIE.send(l_cookie_name,l_cookie_value);
OWA_UTIL.redirect_url(l_original_url);
By omitting the OWA_UTIL.http_header_close, you can still call OWA_UTIL.redirect_url and it will work correctly. Sure, you could pass the URL to a static page that uses javascript to redirect, but that's just not elegant.
Now every page can call a simple function to check the cookie value to see if the user is authenticated, and the user can be redirected back to these same pages after login without having to have an intermediate "confirmation" page just to get around the fact that you can't read a cookie immediately after setting it.
redirect
mo, April 18, 2006 - 7:04 pm UTC
Tom:
I had the same problem described in prvious post about redirection and obviously the SET cookie routine was causing it. So i Did change the SET_COOKIE function to this:
OWA_UTIL.mime_header('text/html',false);
OWA_COOKIE.send(l_cookie_name,l_cookie_value);
OWA_UTIL.redirect_url(l_original_url);
OWA_UTIL.http_header_close;
WOuld this have any effect on something else or it is still valid?
April 19, 2006 - 8:19 am UTC
seems to me it is what the guy above was suggesting. what you need to do is
a) understand the headers (what is valid)
b) ensure they are getting output correctly
opening the mime header and then outputting the cookie followed by the location redirect is "valid" yes.
If you closed the header (as examples for sending cookies would necessarily do), then the location redirect - which must be in the header - would get munged as it would not be in the header anymore.
kevin, June 27, 2006 - 5:37 pm UTC
Hi Tom,
How can I rediret the page when the condition is meet in PL/SQL page similar like:
DECLARE
my_num number := 2;
if my_number > 2 then
SELECT name
FROM test_table
WHERE name_id = :P2_NAME_ID;
else
-- GO TO PAGE 3 AND ALSO PASS THE VALUE
-- OF P2_NAME_ID TO PAGE 3
end if;
end;
Thank you,
June 28, 2006 - 7:40 am UTC
owa_util.redirect_url
Kevin, June 28, 2006 - 8:58 am UTC
owa_util.redirect_url('f?p=&APP_ID.:3:&APP_SESSION.::NO::P3_ID:');
This "owa_util.redirect_url" is just redirect to Page 3. How can i pass the primary key like ID to page 3.
Thanks
June 28, 2006 - 9:09 am UTC
what URL would you have used to pass this to page 3 "normally"
Look at the URL in your browser right now, you'll see how parameters are passed in htmldb.
Kevin, June 28, 2006 - 9:18 am UTC
owa_util.redirect_url('f?p=&APP_ID.:3:&APP_SESSION.::NO::P3_ID:');
with that code above when i the codition is meet and it redirect to page 3 and the url appear is "</code>
http://servername.local:7777 <code>- Form 1" and it popup the message like:
ORA-01403: no data found
Error Failure to fetch row.
redirection
A reader, January 13, 2010 - 1:13 pm UTC