Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling JSP from servlet 404 error  RSS feed

 
Louise Blue
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im getting the 404 error when im trying to call a jsp file from this servlet.
Is this even the right way to do it?
Here is my doPost method:


 
Louise Blue
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops!! ill remember that the next time...Thank you!!
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Morning Louise,

Can you share your directory structure here ? This issue may be just resolved by correctly referencing your JSP page . Also Keep in mind that all URL paths starting with a backslash "/" means they are relative to context root the and the context will not get pre-pended.
Java docs wrote: The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.
 
Louise Blue
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how my structure look like:

MinTest (Project name)
Javaresources
Src
Pakke2
GenerelServlet(the servlet that I use)
Webcontent
editio
bootstrap
index2.jsp
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright . And what URL does it show in the browser when it gives the 404 error. It should be http://localhost:8080/MinTest/editio/bootstrap/index2.jsp in order to work fine. Also have you tried to run your code by removing the backslash '/' from the URL in the request dispatcher parameter ?
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saif Asif wrote: It should be http://localhost:8080/MinTest/editio/bootstrap/index2.jsp in order to work fine.

The source directory structure and deployment directory structure may be different. Its the deployment directory structure that really matters.


Here your path to the JSP starts with "/" meaning you are referring this JSP from the ROOT of your web-app.
Your WEB-INF structure should reflect this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!