[英]Page redirecting in a web application at server side
I have two websites say 我有两个网站说
1. firstwebsite.com
2. secondwebsite.com
All the pages in firstwebsite are static. firstwebsite中的所有页面都是静态的。 Now I want to move all pages in firstwebsite.com to secondwebsite.com.
现在,我想将firstwebsite.com中的所有页面移至secondwebsite.com。 I want to shutdown all servers of firstwebsite.com
我想关闭firstwebsite.com的所有服务器
I also want to make sure that when the URL firstwebsite.com/** should redirect to secondwebsite.com/** 我还想确保当URL firstwebsite.com/**重定向到secondwebsite.com/**时
firstwebsite.com/abc.html should redirect to secodnwebsite.com/abc.html firstwebsite.com/abc.html应该重定向到secodnwebsite.com/abc.html
I am using springs. 我正在使用弹簧。 Can some one guide me how to do it.
有人可以指导我怎么做。 Later I also want to do some processing based on device from which request is sent.
稍后,我也想根据发送请求的设备进行一些处理。
It would be really great if I can get some references for above. 如果能从上面获得一些参考,那将是非常不错的。
Java EE has Filters which run in every request. Java EE具有可在每个请求中运行的过滤器。 All request to
firstwebsite.com
will be handled ,first in the code, by a filter then redirected to secodnwebsite.com
. 对
firstwebsite.com
所有请求将首先在代码中由过滤器处理,然后重定向到secodnwebsite.com
。
public class RedirectionFilter implements Filter {
/**
* Default constructor.
*/
public RedirectionFilter () {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String servletPath = request.getServletPath();
if (servletPath.endsWith(".html")) {
response.sendRedirect("http://secondwebsite.com" + servletPath);
}
else {
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
Do not forget to add this filter to deployment descriptor (web.xml). 不要忘记将此过滤器添加到部署描述符(web.xml)。 Put it to first order if you have another filters so that this filter runs first.
如果您还有其他过滤器,则将其放在第一位,以便该过滤器先运行。
<filter>
<display-name>RedirectionFilter</display-name>
<filter-name>RedirectionFilter</filter-name>
<filter-class>your.package.RedirectionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RedirectionFilter</filter-name>
<servlet-name>Servlet which firstwebsite.com run</servlet-name>
</filter-mapping>
See also 也可以看看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.