• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with RequestDispatcher

 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I've a register.jsp form, when an user submits this form, the request goes to a Servlet which controls if all fields are correctelly filled. if not, the Servlet sends the user to the register.jsp again to fill the form again.

The problem is when the Serlvlet makes a RequestDispatcher, all the images, css, en links goes away.
The 2nd problem is if I want to submit that form again, the server says that the Servlet does not exists.

URL of the register form: http://localhost:8080/website/registreren.jsp
URL when the form is submitted: http://localhost:8080/website/servlet/Register
URL when I try to submit the form again: http://localhost:8080/website/servlet/servlet/Register

The error that I get:
javax.servlet.ServletException: Class `servlet' was not found in classpath.

register.jsp



Register.java


Could someone please help me to fix this problem?

Abu Romaysa
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a hunch about your second problem. When you get a request dispatcher from a servlet context, the pathname that you pass is interpreted as relative to the current context root. Try using getContext() instead, as it is interpreted relative to the server's document root instead. You need to change the "adres" string to represent the correct path to te jsp though.
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
As given in the thrid URL: http://localhost:8080/website/servlet/servlet/Register

I guess there is a registreren.jsp also present in the path website/servlet
That is being called when the request is forwarded from the servlet
and when u submit the form again, the path to which it is getting forwarded is as /servlet/servlet/Register
and Register.java is not found in the path /servlet/servlet/
So, its giving the error.
javax.servlet.ServletException: Class `servlet' was not found in classpath

please confirm if anything like this is happening

Thanks and Regards,
Ani
 
Adeeb Abdul Karim
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of
<form action="servlet/Register" method="post" name="registerForm">
try to use
<form action="/servlet/Register" method="post" name="registerForm">
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<form action="/servlet/Register" method="post" name="registerForm">


It is not a good idea to put the preceeding '/' in a relative link.
Doing so means that you have to include the contextName which makes your app less portable.

The simplest way to avoid these issues is to map all of your servlets in your deployment descriptor so you don't need to keep track of your file hierarchy.

SimpleMVC in http://simple.souther.us has working examples of both the requestDispatcher and of servletMappings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!