一般服务器内部跳转是相对路径,其他的都是绝对路径比较好,这样报错比较少
而关于绝对路径,一般就在相对路径前加上绝对地址,讲不清了,上码
建一个EncodingFilter过滤器
package com.dodoke.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
* Servlet Filter implementation class EncodingFilter
*/
public class EncodingFilter implements Filter {
/**
* Default constructor.
*/
public EncodingFilter() {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
//这部分是网上copy的,也不用记,记不住的
HttpServletRequest request = (HttpServletRequest) req;
String basePath = request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath();
request.setAttribute("basePath", basePath);
System.out.println(basePath);
// pass the request along the filter chain
chain.doFilter(req, res);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
然后在xml里配置一下
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.dodoke.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>