[英]Redirect to setup if config is missing
I'm trying to create a basic java web app using servlet 3.0. 我正在尝试使用Servlet 3.0创建一个基本的Java Web应用程序。 Now, my application needs to run through a basic setup page/form so it knows where to store config files etc. What would be a good way to implement this?
现在,我的应用程序需要运行一个基本的设置页面/表单,以便它知道将配置文件存储在何处。什么是实现此目的的好方法?
I was thinking of a filter, but since i cant do a redirect, that seems like the wrong way. 我当时在考虑过滤器,但是由于我无法进行重定向,因此这似乎是错误的方法。
Suggestions? 有什么建议吗?
Seems to me that a Filter
would be a great approach to what you're trying to accomplish: 在我看来,
Filter
将是您要完成的目标的绝佳方法:
@WebFilter
public class ConfigFilter implements Filter {
@Inject
private SessionBean session;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String requestURI = ((HttpServletRequest) request).getRequestURI();
if(!session.hasConfig() && !requestURI.startsWith("/configWizard.xhtml")) {
((HttpServletResponse) response).sendRedirect("/configWizard.xhtml");
}
else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.