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

  • SEARCH
  • Home
  • 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 5989721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:08:31+00:00 2026-05-22T23:08:31+00:00

The web-app I’m currently building follows MVC. I’ve structured the servlets in a way

  • 0

The web-app I’m currently building follows MVC. I’ve structured the servlets in a way such that they each handle related actions (so, one servlet may be responsible for all actions relating to setting up a user’s account, while another may be used for user correspondance). Currently I have an “action” parameter attached to all query strings (for GETs), and request bodies (for POSTS), and use that in order to determine what action to take in these “related action” servlets.

In other words, my code is structured somewhat like this:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
{
    String action = request.getParameter("action");

    if(action.equals("login"))
    {
        .....
    }
    else if(action.equals("createAccount"))
    {
        ....
    }
    else if(action.equals("changePassword"))
    {
        ....
    }
    ..........
}

I’m relatively early in the development process, and as of now, I don’t find any maintainability issues coming from this design. As per MVC, all the servlets do is call the methods of my utility classes; no actual work is done in them except for sending the responses back to the client. But by browsing SO, I’m coming across the sentiment that even moderately-sized (~10 or less “elses”) if-else statements are code-smell and suggest the user isn’t doing things the “OOP way”.

Is there a better way to filter the types of requests coming in to my servlets? I’d like to be able to improve the maintainability of my app, but unwilling to implement OOP features just because they’re OOP (similar to how people despise purists who insist on rigid encapsulation, to the point where they have 24 one-line getters/setters).

  • 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-22T23:08:32+00:00Added an answer on May 22, 2026 at 11:08 pm

    If you’re just looking to avoid code-smell with the the large if statements and be a bit more OO, you can try using reflection-style instantiation if you can get your utility classes to implement the same interface. Basically, the value of the action parameter would be a representation of an actual classname (or a portion thereof, with appropriate values prepended or appended).

    String action = request.getParameter("action");
    Class clazz = Class.forName(action);
    UtilityInterface utilityObj = (UtilityInterface)clazz.newInstance();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web app that has a database backend. In the past I'm
Background I have a web app that will create an image from user input.
I have a web app, that consumes a web service. The main page runs
Our web app is rendered totally on the browser. The server only talks to
My web-app records users via webcam and microphone. I want to use HTML/JS for
A web app written in Python is planned, Django is a leading contender as
I have a web app hosted in IIS7 and I have set the appPool
In my Django web app, an event's status changes from 'upcoming' to 'completed' at
I have a GWT+GAE web app with several service and modules. I am using
While deploying a dwr web app, i'm continuously getting this error. I dont know

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.