-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Can't seem to find anywhere in ZK to return "moved permanently" - Any ideas?
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
<zk>
<window border="normal" title="New">
<div>New index page!</div>
</window>
</zk>
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");
}}
<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.
Asked: 2011-09-12 09:41:18 +0800
Seen: 482 times
Last updated: Oct 16 '11