Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am building a Dynamic web application in Eclipse.

In my Login.java servlet, I want the doGet() method to perform some logic (i.e. check if the user is already logged in) and open the page login.jsp located in the webapp folder, as seen in the image.

I've tried variations of

request.getRequestDispatcher("/src/main/webapp/login.jsp").forward(request, response);

but I keep getting 404 errors that The requested resource is not available..

How do I determine the proper path that the system wants in order to display this page?

Project Structure

share|improve this question
2  
src/main/... are Maven conventions for building your project. They do not exist at deployment/runtime. –  Sotirios Delimanolis 2 days ago
2  
simply try request.getRequestDispatcher("/login.jsp").forward(request, response); –  user3218114 2 days ago
    
@user3218114 Thanks, surprisingly, it worked! –  Imray 2 days ago

1 Answer 1

up vote 2 down vote accepted
  • If the path begins with a / it is interpreted as relative to the current context root (it means jsp is directly placed under webapp or webContent folder in the project)

    For example:

    request.getRequestDispatcher("/login.jsp").forward(request, response);
    
  • If the path does NOT start with forward slash,it is considered relative to the original request.

Read more...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.