user1097772
user1097772

Reputation: 3549

404 not found jsp

This is post method of my login Servlet

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String login = request.getParameter("login").trim();
    String password = request.getParameter("password");

    User user = getUsersDao().login(login, DigestUtils.shaHex(password));

    if (user == null) {
        request.setAttribute("login", login);
        request.setAttribute("error", "Wrong username or password.");
        forward(request, response, LOGIN_JSP);
    } else {
        request.getSession().setAttribute(USER_SESSION, user);
        response.sendRedirect(LOGGED_IN_URL);
    }
}

where LOGGED_IN_URL is "WEB-INF/jsp/index.jsp";
and index.jsp exist on this addres, this doesn't work only after login. The if condition on user is ok (I checked it by setting it on false).

Why does it happens?

Upvotes: 0

Views: 1617

Answers (1)

BalusC
BalusC

Reputation: 1109262

Resources in /WEB-INF folder are not publicly accessible (otherwise the enduser would be able to see sensitive information such as datasource username/password in web.xml by just opening it directly).

You need to put the publicly accessibe JSP file outside the /WEB-INF folder.

LOGGED_IN_URL = "/index.jsp";

and redirect as follows

response.sendRedirect(request.getContextPath() + LOGGED_IN_URL);

Resources in /WEB-INF are only available for forward and include.

Upvotes: 2

Related Questions