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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:17:38+00:00 2026-05-23T10:17:38+00:00

I need a little advise as to how to structure classes in my web

  • 0

I need a little advise as to how to structure classes in my web application.I have a webstore where items can be added,edited,listed and deleted.When I tried to write servlets for this,it came out like

    ItemAddServlet ,ItemEditServlet,ItemsListServlet,ItemDeleteServlet,
ManufacturerAddServlet,ManufacturerEditServlet,ManufacturerListServlet

ItemAddServlet is

public class ItemAddServlet extends HttpServlet {
    private ItemDaoFactory bfactory = ItemDaoFactory.getInstance();
    private ItemDaoImpl itemdaoimpl = (ItemDaoImpl) bfactory.getDao();
    private ManufacturerDaoFactory mfactory = ManufacturerDaoFactory.getInstance();
    private ManufacturerDaoImpl mandaoimpl = (ManufacturerDaoImpl) mfactory.getDao();

    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        List<Manufacturer> manufacturers = mandaoimpl.findAllManufacturers();
        request.setAttribute("manufacturers",manufacturers);
        RequestDispatcher dispatcher = request.getRequestDispatcher("itemaddedit.jsp");     
        dispatcher.forward(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{   
        String name = request.getParameter("name");     
        String price = request.getParameter("price");
        String manId = request.getParameter("manufacturer");
        Manufacturer manufacturer = mandaoimpl.findManufacturerById(Long.parseLong(manufacturerId));    
        Item item = new Item();
        item.setName(name);     
        item.setPrice(Float.parseFloat(price));
        item.setManufacturer(manufacturer);     
        itemdaoimpl.saveOrUpdateItem(item);     
        response.sendRedirect("listitems");
    }
}

The other servlets are similar,with changes according to the logic involved..

I have mapped the url-patterns to servlets as below

...
<servlet-mapping>
  <servlet-name>itemaddservlet</servlet-name>
  <url-pattern>/createitem</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>itemeditservlet</servlet-name>
  <url-pattern>/edititem</url-pattern>
 </servlet-mapping>
  <servlet-mapping>
  <servlet-name>itemlistservlet</servlet-name>
  <url-pattern>/listitems</url-pattern>
 </servlet-mapping>
...

I am aware that there are too many servlets here ..It doesn’t look like a good design..Can I do the add/edit /list/delete functionalities using just one servlet?That would shrink my servlets to

ItemServlet,ManufacturerServlet

Is that the correct way of doing this?How would I map the url-patterns in this case? /createitem /edititem /listitems all will map to ItemServlet?

I would be grateful if someone can point out better ways of structuring the code..

thanks

mark

  • 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-23T10:17:39+00:00Added an answer on May 23, 2026 at 10:17 am

    There are several frameworks for helping out with this pattern. If you’re wanting to use pure servlets, the easiest thing would be to pass a parameter to the servlet indicating the operation you’re trying to perform (i.e. create, edit, list).

    A couple frameworks that you might find helpful are below

    • Spring
    • MVC Struts
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little advice on nesting HTML elements. I have a general structure
Need a little help with a SQL / ActiveRecord query. Let's say I have
I need a little push in the right direction. Here's my problem: I have
I need a little help brainstorming on a query. I have a sales table
I'm writing a little application for my BlackBerry and I need to send some
I need some advice on a little project im doing. I have a database
For a little free fruit site, I have the following model relationship: 3 classes
I am building an application at work and need some advice. I have a
I'm new to Big-O notation, so I need a little advice. Say I have
I have just taken over maintenance of a large web application which is over

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.