【发布时间】:2010-09-19 05:50:46
【问题描述】:
我正在开发一个使用 JSF 的 Web 应用程序。我在“web”下有一个名为“admin”的文件夹,在“admin”文件夹下有几个 jsp 页面。我可以访问“web”下的 jsp 页面,但是当我尝试访问“admin”下的页面时,我得到“404-Requested resource cannot be found” 我的应用程序的“context.xml”是这样的:
<Context antiJARLocking="true" path="/MyApp"/>
这个东西适用于我的本地 tomcat,但是当我将它部署到我的网络托管服务提供商 tomcat 时,我遇到了上述问题。 我究竟需要做什么来解决这个问题。
这里是我在 Hosting 上的应用程序的 server.xml 提供的 tomcat:
<Host name="myapp.com" appBase="/home/myapp/public_html">
<Alias>www.myapp.com</Alias>
<Context path="" reloadable="true" docBase="/home/myapp/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
或者我需要将 URL-Mapping 添加到我的 web.xml 吗?
我在 web.xml 中有以下 servlet 过滤器,用于 '/admin/*' url-pattern
<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>com.myapp.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
过滤代码如下:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
lgMgr.logDebug("doFilter() is called...");
String validuser = null;
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession session = req.getSession(true);
//If authorization key not in session, redirect to login page.
validuser = (String) session.getAttribute(Common.AUTH_USER);
if(validuser != null) {
lgMgr.logDebug("doFilter(): User is allowed to access the page...");
//If the user is allowed access to the URI, let the flow proceed as normal
chain.doFilter(request, response);
return;
} else {
lgMgr.logDebug("doFilter(): User is not allowed to access the page, redirecting user login...");
//User not allowed access - redirect to login page
res.sendRedirect(req.getContextPath() + "/AdmLogin.jsf");
return;
}
}
【问题讨论】: