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 7398287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:51:06+00:00 2026-05-29T03:51:06+00:00

I am using a servlet that is taking parameters from a registration form, what

  • 0

I am using a servlet that is taking parameters from a registration form, what I am doing at present is using a java class that will process on those parameters and store them in Database but I feel like the way I am using this class is wrong. My code is like this:

UserRegister ureg=new UserRegister(name,age,sex,country);

And that is all, my constructor in the class will do the entire job from processing the data to storing it in db by calling methods in the UserRegister class on its own.

Is it the right approach, or there is any better way of doing this?

EDIT: my UserRegister class will do just some processing on the data and it will call a business layer to store the data, it itself is not going to interact with the database.
What I am asking is what approach is to be followed when you have a class where after initializing there are just a fixed series of steps to be performed inside it

  • 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-29T03:51:07+00:00Added an answer on May 29, 2026 at 3:51 am

    my constructor in the class will do the entire job from processing the data to storing it in db

    Wrong. Never program this way.

    Come out of c’tor ASAP after intializing the basic necessity of it’s class.

    The method in which UserRegister object is created. use that method to call methods on ureg object.

    For example:

    public void processRequest(name, age, sex, country)
    {
        UserRegister ureg=new UserRegister(name,age,sex,country);
        ureg.updateSomeFields();
        ureg.doSomeBusinessLogic();
        ureg.prepareDBData();
        ureg.storeInDb();
    }
    

    This is only an example to improve your current design. however you should have some utility classes also. class UserRegister should have data and behaviour which represent a User, only a User.

    Design Utility classes such that they take input in a format, do some calculation and then return the output data to it’s caller. So, whenevr processRequest method needs a job to be done, it doesn’t do it by itself but calls another method (it may be in same class or some other class)

    EDIT:

    What I am asking is what approach is to be followed when you have a class where after initializing there are just a fixed series of steps to be performed inside it

    It depends on the nature of those steps. Find out how are they related. are they related to User? if yes, put them as methods in User class. if not, combine related steps together, create a class with meaning full name and use it. When creating a separate class, try to design in such a way they can be used as utility and not only for the current purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet that request a geolocation from another server using an http
I'm writing a Java servlet that I'm planning to deploy on Amazon AWS using
I have an applet that communicates with a servlet using Http (Not sockets). Currently,
i am trying to upload an image from a jsp page using servlet. but
I am developing a chat website using jsp/servlet.I will be hosting my website on
How can I upload files to server using JSP/Servlet? I tried this: <form action="upload"
We're creating a web system using Java and Servlet technology (actually Wicket for the
I'm using restTemplate to make a rquest to a servlet that returns a very
I have a main Servlet that processes post/get requests. I am using connection pooling
We have a BPEL process that is taking characters (e.g. Chinese) and attempts to

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.