html - getRequestDispatcher dispatching jsp but not html
问题描述
I am running google app engine and using JAVAEE.
I have a two filters but only one is configured with restrictions.
WEB.XML
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<filter>
<filter-name>connexionFilter</filter-name>
<filter-class>AHSFilters.connexionFilter</filter-class>
</filter>
<filter>
<filter-name>restrictFilter</filter-name>
<filter-class>AHSFilters.restrictFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>connexionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>restrictFilter</filter-name>
<url-pattern>/client</url-pattern>
<url-pattern>/admin</url-pattern>
</filter-mapping>
</web-app>
- I first login so I can go trough the first filter.
- I change my url to
localhost:8080/client
my connexion filter is as so:
package AHSFilters;
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;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class connexionFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
HttpSession session = req.getSession();
if(session.getAttribute("sessionUser") != null)
chain.doFilter(req, resp);
if (req.getHeader("X-Requested-With") != null)
chain.doFilter(req, resp);
else
req.getServletContext().getRequestDispatcher("/").forward(request, response);
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
my servlet is as so:
package AHSServlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet(
name = "ClientServ",
urlPatterns = {"/client"}
)
public class ClientServ extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.getWriter().flush();
this.getServletContext().getRequestDispatcher("/restrict/client/test.jsp").forward(request, response);;
}
}
when my file is setted to test.jsp
I go to the correct page, but when I rename it to test.html
and of course change the path in getRequestDispatcher
I get redirected to my login page (/
route).
So I have to files /restrict/client/test.jsp
i get the correct response
and /restrict/client/test.html
I go back to the signin page.
I've tried putting a simple hello
in test.html
also tried with valid html page with the same result. Is there any settings I'm missing in order to allow html?
Where could it come from? Any help is greatly appreciated.
解决方案
我认为为了做到这一点,你需要很少的配置。在web.xml
编写配置代码
<jsp-config>
<jsp-property-group>
<url-pattern>*.html</url-pattern>
</jsp-property-group>
</jsp-config>
为了更好地理解,您可以检查
推荐阅读
- php - 试图在 foreach 循环中获取非对象的属性
- c# - Xamarin 比 listview 更快
- terraform - 是否可以在 Terraform 中“改变”模块的源路径?
- c++ - C++/Arduino 如何从类内部引用全局变量
- r - 混合模型残差的 Durbin Watson 检验
- javascript - 如何更新生产 MongoDB 模式而不丢失以前保存的数据?
- python-3.x - 我有一个在制作矩阵的函数中未使用的局部变量
- msal - 从 Microsoft Authentication Library (MSAL) for .NET 获取访问令牌,无需登录到 Web 服务器
- python - 有没有办法用算术运算符将数组附加到列表中?
- javascript - Event.source 在 BroadcastChannel 中返回 null - javascript