top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to restrict the no of user in the struts web applcation?

+5 votes
613 views
How to restrict the no of user in the struts web applcation?
posted Dec 13, 2013 by Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Would you like to provide some more details...
@prasad: This is a very open question, will you be more precise to the question.

2 Answers

+2 votes
  1. Place the SessionID in the DB column against every session created by the user.
  2. This will provide count of the sessions currently active for the current user(s).
  3. Use a LoginServlet to check on the number of users having the active session (query the User_session table (from the DB) and check against the count.)

But in summary I agree this is a very open question and require more thoughts and inputs before answered precisely. Let me know if it serves the purpose.

answer Dec 13, 2013 by Naveena Garg
+1 vote

it is intended in a "container" way, this should go:

@WebFilter("/*")
public class RequestFilter implements Filter
{
    private static final int THRESHOLD = 5;
    private static Map<String, AtomicInteger> accessMap = new HashMap<String, AtomicInteger>();

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
    {
        HttpServletRequest request = (HttpServletRequest) servletRequest;

        AtomicInteger counter = accessMap.get(request.getRequestURI());
        if(counter == null) counter = new AtomicInteger();

        if(counter.incrementAndGet() < THRESHOLD)
        {
            filterChain.doFilter(servletRequest, servletResponse);
        }

        counter.decrementAndGet();
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException
    {
        // nothing to do
    }

    @Override
    public void destroy()
    {
        // nothing to do
    }
answer Dec 14, 2013 by anonymous
Similar Questions
0 votes

I have a very minimal struts app I wrote some years ago. I want to upgrade it from 2.3 to 2.5. I'm wondering what requirements would allow the use of the essential dependencies jar. I am using only jstl tags, no struts tags. And my app is pretty simple.

...