cancel
Showing results for 
Search instead for 
Did you mean: 

How to redirect a page

Former Member
0 Kudos

Hi,

I try to create a page the is redirected to another page, but don't work.

What can I do? When the page is redirected the top level navigation must be refreshed?

I write this code:

IPageContext myContext = PageContextFactory.createPageContext(request, response);

if (myContext == null) {

System.out.println("htmlb service did not start up as expected.");

}

String URL = path to page in PCD;

Document mydocu = myContext.getDocument();

mydocu = myContext.createDocument("Pagina da redirigere");

mydocu.setHeadRawText("<meta http-equiv=\"refresh\" content=\"1; url=" + URL + "/>");

Anybody can help me?

Thanks in advance.

regards,

Stefano

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Got it to work using some javascript:

response.write("<script language='javascript'>top.location.href='http://www.google.com';</script>");

Former Member
0 Kudos

You can use the following code to do a redirect. The new URL will load in the entire window (not in content area).

From within your DynPage:

IPortalComponentRequest request=getRequest();

String url="http://www.google.com";

request.redir(url);

javadoc for redirect is to be found here:

https://media.sdn.sap.com/javadocs/NW04/SP12/runtime/com/sapportals/portal/prt/component/IPortalComp...

Johan

Former Member
0 Kudos

I tried that and it did not work. Is it because I am trying to write a Java iView instead of a WebDynPro? Here is my sample class:

public class ExternalURLiView extends abstractPortalComponent{

public void doContent(IPortalComponentRequest request, PortalComponentResponse response){

String url="http://www.google.com";

request.redirect(url);

}

}

Former Member
0 Kudos

Hi,

You can make a call to the JS method doNavigate of the EPCF, here is an example.

parent.EPCM.doNavigate('ROLES://<locationOfYourPage>,0,null,null);

You can put this in the onLoad event to get it triggered right when the iView is loaded. This will refresh the Top Level Navigation also.

Hope this helps.

Ankur

Former Member
0 Kudos

Hi Ankur,

thanks for your reply, but how can get the method Onload?

Thank in advance.

Kind regards,

Stefano

Former Member
0 Kudos

I meant the OnLoad event of HTML..

for e.g. I am calling this small alert function in the onload event.. similarly you can put the EPCM.doNavigate

<HTML>

<Body onload="javascript:alert('hi')">

</Body>

</HTML>

Hope this helps,

Thanks

Ankur

Former Member
0 Kudos

Stefano,

the NavigationTarget trick I showed you in the other thread

should solve this issue. The toplevel navigation will get updated if you use this parameter

Regards,

Dominik

Former Member
0 Kudos

Hi Dominik,

I'm sorry but I don't able to create the iview for redirect the page; I try to use the Navigation Target but the page is loaded into the iview.

Please you give me, step by step, the solution?

Thank you very very much!

Kind regards,

stefano

Former Member
0 Kudos

Hi Stefano,

hmm... then you might succed in using some javascript for the redirection instead on a meta refresh. For instance location.replace(theURL);

Sorry, I'm unable to verify this right now, as I don't currently have access to a portal.

HTH,

DOminik

jcvidaller
Participant
0 Kudos

Hi,

I don't know if this solves your problem, but this is an iView that redirects to www.google.es:

<pre>

import java.io.IOException;

import com.sapportals.portal.prt.component.*;

import javax.servlet.http.HttpServletResponse;

public class Redirect extends AbstractPortalComponent

{

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

HttpServletResponse resp = request.getServletResponse(true);

try {

resp.sendRedirect("http://www.google.es/");

} catch (IOException e) {

e.printStackTrace();

}

}

}

</pre>

Hope it helps,

jc!

Former Member
0 Kudos

This works great, except do you know how to make your google redirect example to load outside of SAP EP but in the same window? Right now the external page still loads with in the context of the SAP EP frames. I want the external page to replace SAP EP.

Thanks,

Steve

Former Member
0 Kudos

I used this one for my JSP Dyn Page. Thank you.

IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();

HttpServletResponse resp = request.getServletResponse(true);

try

{

resp.sendRedirect("http://URL");

}

catch (Exception exp)

{

state = ERROR;

this.setJspName("Error.jsp");

}