1

I'm trying to run my web application based on javax.mvc, but I get 404 error. I think there should be an issue related to the application path, but I don't know exactly what's wrong.

XAMPP is installed and IntelliJ idea is configured to run tomcat7 as the web server.

enter image description here

Application code:

@ApplicationPath("web")
public class StoreApplication extends Application {
    
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> set = new HashSet<>();
        set.add(ProductController.class);
        return set;
    }
}

Controller:

@Controller
@Path("products")
public class ProductController {
    @Inject
    private Models models;
    
    @GET
    public String list() {
        models.put("products", Product.list());
        System.out.println("helllo");
        return "/WEB-INF/jsp/list.jsp";
    }
}

This is a maven project. The build process is done with IntelliJ idea default settings.

Base url is set in StoreApplication.java as web with application path.

The war url is http://localhost:8080/elearning_war/ as depicted in the picture.

And the controller path is products. So I expect to show a list of products in http://localhost:8080/elearning_war/web/products, but instead, I get a 404 error page.

jccampanero
  • 50,989
  • 3
  • 20
  • 49
alex
  • 7,551
  • 13
  • 48
  • 80
  • Why do you need XAMPP for this application, which obviously is Java-based? (By the way, really Tomcat 7? See http://tomcat.apache.org/whichversion.html ) How did you build your project? Which versions were used? And, the big secret, which URL gives you the 404 HTTP response, and how did you test it? Withoud details, nobody can help. – t0r0X Nov 27 '20 at 00:16
  • @t0r0X the question is updated – alex Nov 27 '20 at 04:27
  • Do you have a sample project to check? – Andrey Nov 27 '20 at 08:40
  • What do you see for `http://localhost:8080/elearning_war/` and `http://localhost:8080/elearning_war/products` pages? – Andrey Nov 27 '20 at 08:41
  • Does this answer your question? [How to set up JAX-RS Application using annotations only (no web.xml)?](https://stackoverflow.com/questions/9373081/how-to-set-up-jax-rs-application-using-annotations-only-no-web-xml) – Andrey Nov 29 '20 at 15:47
  • @Andrey this is an issue concerned with Tomcat. changing server to glassfish5 solved the problem.i think there should be added some extra repositories when using tomcat – alex Nov 29 '20 at 18:56

1 Answers1

0

In my opinion, because of @ApplicationPath("web") the URL should be http://localhost:8080/web/products.

t0r0X
  • 4,212
  • 1
  • 38
  • 34