Authenticating and redirecting six specific users
What is common?

Let's take a look at the cases that look similar and see what is common among them.

case &lt;THIS PART IS DIFFERENT&gt;:
if(PASSWORD.equals(password)) {
    request.getSession(true).setAttribute("username", username);
    response.sendRedirect(&lt;THIS PART IS DIFFERENT&gt;);
}


Okay, so we have essentially that one string (username) leads to another string (a redirect). One thing is pointing at another. Oh, a map/dictionary!

Map&lt;String, String&gt; redirects = new HashMap&lt;&gt;();
redirects.put("client1", "app1/apk-1-index.html");
redirects.put("client2", "app2/apk-2-index.html");
redirects.put("client3", "app3/apk-3-index.html");
....


(Yes, you could use a simple for-loop to setup this)

Then we have to determine first of all: Is our username in the map or not? If it isn't, that corresponds to our default case.

String redirect = redirects.get(username);
if (redirect == null) {
    response.sendRedirect("/Test2/index.jsp");
    return;
}


So, if it is in the map, then let's do the common things and use the redirect we picked from the map:

if (PASSWORD.equals(password)) {
    request.getSession(true).setAttribute("username", username);
    response.sendRedirect(redirect);
}