Java EE 8 MVC: How do you startup with controller?

849 views Asked by At

I am aware that Java EE 8 MVC is shiny and new and might not have everything I hoping there is a way to call a view from a controller on startup

@Path("home")
@Controller
public class HomeController {

    @Inject
    Models models;

    @Inject
    public UIAccess uiaccess;

    @GET
    @Path("index")
    public String index() {
        models.put("sidebar", uiaccess.sideBar());
        return "home/index.xhtml";
    }    
}

Is there any way that the web.xml can be setup to call the view

<welcome-file-list>
    <welcome-file>app/home/index.xhtml</welcome-file>
</welcome-file-list>

This does not work app/controller_name/view when place in the web.xml

I know servlet class can be called in startup but want about controllers.

1

There are 1 answers

0
AudioBubble On BEST ANSWER

I encountered same problem before, web.xml seems doesn't support for MVC path yet.

My opinion you may select 2 option below

  1. Use JSP or html as welcome file.
  2. Use MVC as default handler and set as root context. you may learn more by sample.