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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:36:22+00:00 2026-06-11T10:36:22+00:00

I am currently working on some web dev project in Java, i have implemented

  • 0

I am currently working on some web dev project in Java, i have implemented a frontcontroller, which job is to instantiate new controllers, depending on the path.

So when the user is running ?q=user/login ex. the front controller should instatiate the UserController, that i am trying to do with this piece of code.

    String q = request.getParameter("q");

    try {
        String[] page = q.split("/");
        // Make first char upper, to match class name conventions.
        page[0] = (page[0].substring(0, 1).toUpperCase() + page[0].substring(1).toLowerCase()).trim();

      Class contDes = Class.forName("dk.elvar.rocks." + page[0]+ "Controller");
      Constructor co = contDes.getConstructor();
      co.newInstance(request, response, page);

This results in a

java.lang.NoSuchMethodException: dk.elvar.rocks.UserController.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at dk.elvar.rocks.FrontController.doGet(FrontController.java:35)

I’ve tryed to look it up at google, and bugs as, declaring a constructor in loaded object, make the class public, is already there.

UserController:

public class UserController extends HttpServlet  {

private final String USERNAME = "Martin";
private final String PASSWORD = "David";

    private static final long serialVersionUID = 1L;
HttpServletRequest request;  
HttpServletResponse response;

public UserController(HttpServletRequest request, HttpServletResponse response, String[] action)  {
    this.request = request;
    this.response = response;

    if(action[1].equalsIgnoreCase("login")) {
        this.renderLoginAction();
    }
    if(action[1].equalsIgnoreCase("val-login")) {
        this.validateLoginAction();
    }
}
  • 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-06-11T10:36:24+00:00Added an answer on June 11, 2026 at 10:36 am

    You probably get this exception because that class does not have a default constructor. You can get a constructor with parameters by passing them to the getConstructor method:

    Constructor co = contDes.getConstructor(
                    HttpServletRequest.class, 
                    HttpServletResponse.class, 
                    String[].class);
    co.newInstance(request, response, page);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project about social networking, where I have some problems
First, some context: I'm currently working on a project in which I use the
Good morning. I am currently working on a Java Web Service project, that is
I am currently working with some users that do not have the .NET Framework
I'm currently working through some exercises in a c++ book, which uses text based
I am currently working on some simple custom allocators in c++ which generally works
I'm currently working on a project with some fancybox (inline content). I'd like to
I have a Websphere Portal application containing several portlets for which I'm currently working
I'm currently working on a web site which involves a data upload process. The
I am currently working on a JAVA web application using JSF, Facelets, JSTL and

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.