Poofpoo
Poofpoo

Reputation: 1

Can't run .jsp pages directly

I'm having a problem using eclipse that recently appeared. When I try to run any .jsp file i get the

404 error resource not available.

However if I run the .java file I get the page loaded up. executing the following java code I can get the page to run but it still wont redirect the page after the correct button is pressed. I get no other error messages other than the one I already mentioned.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");

    String action = null, address = null;
    address = "/WEB-INF/PhonebookMain.jsp";
    action = (String) request.getParameter("action");

    if(action == null){
        action = "nema";
    }
    if(action == "nema"){       
    }else
    {
        if(action == "Unos"){
            address ="/WEB-INF/Unos.jsp";
        }

        if(action == "Izmjena"){
            address = "/WEB-INF/Izmjena.jsp";
        }

    }
    RequestDispatcher dispatcher = request.getRequestDispatcher(address);
    dispatcher.forward(request, response);
}
}

Upvotes: 0

Views: 1436

Answers (2)

JB Nizet
JB Nizet

Reputation: 692181

It's not a bug, it's a feature. All resources under WEB-INF are, by specification, inaccessible from the outside, because that's where your classes, configuration, etc., which should stay private, reside.

People typically put their JSPs under WEB-INF precisely because JSPs are views, and should thus never be executed directly: all the requests should first go to a controller, which then forwards to a view. That seems to be what you're doing here: the servlet is a controller which dispatches to a view. So executing the JSP directly doesn't make much sense: the request should go through the controller first.

Upvotes: 4

user6414296
user6414296

Reputation:

remove the /WEB-INF from urland use /something.jsp then try

if you have all .jsp files inside web-inf folder copy them from there and paste them directly under web-content folder

Upvotes: 0

Related Questions