Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:33:07+00:00 2026-05-16T02:33:07+00:00

I’m trying to set up a site which allows users to create their own

  • 0

I’m trying to set up a site which allows users to create their own page – as a subdomain of the site, and so what I’m currently trying to do is to have a filter which looks at the subdomain, and if it’s not in use, or if it’s reserved, then the user will be forwarded to a page where they choose their subdomain name.

The problem that I have is that when I set an attribute on the ServletRequest object, and then forward using the RequestDispatcher, the filter gets called again – but it can’t see the attribute that I set.

I’ve debugged and watched it work (or not work!), and the attribute is being set, but after the forward, the attribute is not there.

Can someone help explain what’s going on, and how I might fix this??

I should probably also mention that I’m developing for Java Google App Engine.

Here’s my filter code.

import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;



public class SubdomainFilter implements Filter{
    private static Logger log = Logger.getLogger(SubdomainFilter.class.getName());
    private static final String[] RESERVED_SUBDOMAINS = {"admin", "home", "www"};
    private static final String registerPage = "/register_a_page";

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
    }

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
            FilterChain arg2) throws IOException, ServletException {
        //if we've been forwarded, it must have been because of an invalid subdomain
        if(arg0.getAttribute("subdomain") != null) {
            arg2.doFilter(arg0, arg1);
        } else { //otherwise, look at the subdomain and determine what to do
            boolean invalidSubdomain = false;
            try {
                String requestURLInfo = ((HttpServletRequest)arg0).getRequestURL().toString();
                String subdomain = URLUtils.getLowestSubdomainFromURL(requestURLInfo);
                arg0.setAttribute("subdomain", subdomain);
                if(subdomainReserved(subdomain) || subdomainInUse(subdomain)) {
                    invalidSubdomain = true;
                }//Otherwise the subdomain must be valid
            } catch(Exception ex) {
                log.severe("Filter could not get subdomain:\n" + ex.toString());
            } finally {
                if(invalidSubdomain) {
                    RequestDispatcher dispatcher = arg0.getRequestDispatcher(registerPage);
                    dispatcher.forward(arg0, arg1);
                } else {
                    arg2.doFilter(arg0, arg1);
                }
            }
        }

    }

    private boolean subdomainReserved(String subdomain) {
        boolean subdomainReserved = false;
        for(String reservedSubdomain : RESERVED_SUBDOMAINS) {
            if(reservedSubdomain.equals(subdomain)) {
                subdomainReserved = true;
                break;
            }
        }
        return subdomainReserved;
    }

    private boolean subdomainInUse(String subdomain) {
        boolean subdomainInUse = false;
        //TODO: implement
        return subdomainInUse;
    }
    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:33:07+00:00Added an answer on May 16, 2026 at 2:33 am

    I think the problem was that I didn’t declare the following in my web.xml:

    <filter-mapping>
       <filter-name>SubdomainFilter</filter-name>
       <servlet-name>*</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
    </filter-mapping>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.