Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何将所有请求重定向到JSP中的特定页面_.htaccess_Jsp - Fatal编程技术网

.htaccess 如何将所有请求重定向到JSP中的特定页面

.htaccess 如何将所有请求重定向到JSP中的特定页面,.htaccess,jsp,.htaccess,Jsp,我正在用JSP开发一个应用程序,我知道ApacheTomcat不支持.htaccess文件 我想将所有请求重定向到index.jsp以进行URI路由 在.htaccess文件中,我有 Options -Indexes -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] 如何使用To

我正在用JSP开发一个应用程序,我知道ApacheTomcat不支持.htaccess文件

我想将所有请求重定向到index.jsp以进行URI路由

在.htaccess文件中,我有

Options -Indexes -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [QSA,L]

如何使用Tomcat7实现JSP URI重写

您可以在应用程序中使用过滤器来完成此操作

创建过滤器类。大概是这样的:

public class SessionFilter implements javax.servlet.Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {}
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("index.jsp");
        try {
            requestDispatcher.forward(req, res);
        } catch (ServletException e) {
        } catch (IOException e) {
        }
    }
    @Override
    public void destroy() {}
}
然后在部署描述符(web.xml)中包含以下内容:

<filter>
    <filter-name>MySessionFilter</filter-name>
    <filter-class>filters.SessionFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>MySessionFilter</filter-name>
    <url-pattern>*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

MySessionFilter
filters.SessionFilter
MySessionFilter
*
要求
这将把每个请求(
*
)重定向到页面
req.getRequestDispatcher(“index.jsp”)


希望这有帮助

非常感谢,你帮了我很多^^