tags:

views:

54

answers:

1

I am working on a web application which uses JSF. I have a folder called 'admin' under 'web' and I have couple of jsp pages under folder 'admin'. I can access jsp pages under 'web' but when I try to access the pages under 'admin' I get '404-Requested resource cannot be found' The 'context.xml' for my application is something like this:

<Context antiJARLocking="true" path="/MyApp"/>

This thing works on my local tomcat but when I deploy this to my web hosting providers tomcat I have above mentioned problem. What exactly I need to do to fix this problem.

Here is server.xml for my application on the Hosting provides 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>

Or do I need to add URL-Mapping to my web.xml?

I have following servlet filter in the web.xml for '/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>

And the filter code is as follows:

    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;
    }
}
A: 

Files in /WEB-INF are not public accessible. I have no idea why it works locally, but this violates the servlet specification. Also, JSF cannot forward views to JSP pages in /WEB-INF folder, they should be placed in public webcontent (one folder level up above /WEB-INF folder).

BalusC
@BalusC, I tried with your answer, now I have all the pages one level up that is under 'WEB' and I have 'admin' folder inside 'WEB' and some pages inside 'admin'. I am able to access pages under 'WEB' but not under WEB/admin Do I need to add servlet-mapping or something?
Abhishek
No, you don't need. Do you have any servlets or filters or constraints in `web.xml` which might be behaving mad? Also keep in mind that paths/filenames in URL's are case sensitive. It won't work if the folder is called `Admin` and you're using `admin` in URL.
BalusC
@BalusC, Yes I have following filter in web.xml: <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>
Abhishek
The root cause of the problem is most likely in the filter. It's apparently not correctly continuing the chain or dispatching the request. Try disabling the filter and see if it works. Also add some logging statements printing variables of strategic interest and retry.
BalusC
@BalusC, I posted the filter code above, is everything ok with that?
Abhishek
At first glance it looks fine. So the root cause of the problem is to be found at lower levels: is the filter successfully constructed and initialized? Have you in any instance read the server's startup and error logs? Check the log files prefixed with `catalina` (startup) and the domainname like `localhost` (webapp-specific).
BalusC
@BalusC, I have removed the filter still the same problem!
Abhishek
Then I don't know. The problem lies somewhere else than in the as far given information. Do you have full control over the server or is it a 3rd party environment? What happens if you rename the `/admin` folder to `/test` or something like? How about other folders?
BalusC