0

response.sendRedirect() - is there a way to return "moved permanently"

asked 2011-09-12 09:41:18 +0800

Bobzk gravatar image Bobzk
444 1 8

Can't seem to find anywhere in ZK to return "moved permanently" - Any ideas?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-09-20 21:55:45 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi bobzk,
could you explain in more details what is the use case you are trying to implement?

link publish delete flag offensive edit

answered 2011-09-21 05:04:33 +0800

Bobzk gravatar image Bobzk
444 1 8

Hi ashishd,

I have completely re-written my web site so that for example "www.myweb.com/old_directory/index.zul" can now be found at "www.myweb.com/index.zul" for example.

The thing is I have hundreds (or thousands) of references to the old URL in google.

I want to tell Google the page has moved permanently (code 301) rather than moved temporarily (code 302).

response.sendRedirect() seems to send moved temporary.

bobzk

link publish delete flag offensive edit

answered 2011-10-05 07:39:30 +0800

Bobzk gravatar image Bobzk
444 1 8

Hi ashishd,

I know that there have been some problems with the forum and hardware so I guess you are busy but I refreshed this topic to the top just so it doesn't fall off the radar.

Bobzk.

link publish delete flag offensive edit

answered 2011-10-12 22:05:23 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

ZKFiddle-Link

indexnew.zul
<zk>
<window border="normal" title="New">

<div>New index page!</div>
</window>
</zk>

TestComposer.java
package j1vegbfo$v4;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import javax.servlet.http.HttpServletResponse;

public class TestComposer extends GenericForwardComposer{

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
HttpServletResponse response = (HttpServletResponse) Executions.getCurrent().getNativeResponse();
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
Executions.sendRedirect("indexnew.zul");
}

}


index.zul
<zk>
<window border="normal" title="Old" apply="j1vegbfo$v4.TestComposer">

<div>Old index page!</div>
</window>
</zk>

Open it in FF and check Net tab of firbug (you should turn on "persist" flag to see all the Network communication details)
Also it is better done in a servlet filter or in init class doInit() method to save parsing of the page. In above code old page will be parsed and then redirected to new page which doesn't look like a good idea to me but it was quick to reproduce. Hope this helps.

link publish delete flag offensive edit

answered 2011-10-16 05:38:58 +0800

Bobzk gravatar image Bobzk
444 1 8

Thanks ashishd,

That works fine.

Bobzk

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-09-12 09:41:18 +0800

Seen: 482 times

Last updated: Oct 16 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More