Search code examples
jakarta-eejakarta-mvc

MVC redirect causes HTTP Status 500 (Internal Server Error)


I'm currently trying out MVC 1.0 (JSR-371) and I'm facing a problem right now.

I have a controller for my Mainpage which just shows some products.

Here is the code for that:

@Path("/welcome")
@Controller
public class WelcomeController implements Serializable {

    //MORE CODE...

    @GET
    @View(value = "index.jsp")
    public void loadAllProducts() {
        models.put("products", productService.findAll());
        models.put("categories", categoryService.findAll());
    }

    //MORE CODE...

Now I want to build a login for users and I want to redirect to the index page after the login. The problem is, when I just view the index.jsp page, the page is clearly empty (because I won't load the products there), so i thought that I just redirect to the /welcome page but sadly I'm not able to do so.

Here is what i tried:

@Path("/login")
@Controller
public class LoginController implements Serializable {

@Inject
private SessionBean sessionBean;

@POST
public Response logIn(@FormParam("name") String name, @FormParam("password") String password) {
    sessionBean.setCurrentUser(new User());
    return Response.status(Response.Status.SEE_OTHER).header(HttpHeaders.LOCATION, "/webshop/welcome").build();
}

//MORE CODE...

I don't get any exception output, the only thing I see is a HTTP Status 500 (Internal Server Error).

Is there a way to redirect to the loadAllProducts-Request so that i don't have to load the products in my login-Request?

Thanks in advance!


Solution

  • It works now. Just updated to Ozark milestone 2. (1.0.0-m02)