~ Mansukh
Virendrasinh Gohil wrote:Can you please refer "Head First Servlet & JSP" book or any book which explain servlets?
You will learn that there is something named web.xml configuration file which needs to have information of servlets.
which means, while deployment you must have a folder named "servlet" directly in your ROOT of your webapps. (Which server are you using for deployment?)
Virendrasinh Gohil wrote:Great. Now can you tell me what is the deployment structure.
Here you are requesting a servlet usingwhich means, while deployment you must have a folder named "servlet" directly in your ROOT of your webapps. (Which server are you using for deployment?)
Amit ChaudhariC wrote: Context path is /ServletTest
--- This will tell you the ROOT of the webapp.($TOMCATHOME/webapps/)
uri is : /ServletTest/FormServlet
-- This tells you the servlet path from the context
path is : /FormServlet
-- how you can call the servlet while submitting the form.
Instead of
form method = "get" action = "http://localhost:10139/servlet/FormServlet">
try using
form method = "get" action = "/FormServlet">
BTW, it is always good idea to start deploying the web app as a war in tomcat for learning purpose.
~ Mansukh
Mansukhdeep Thind wrote:
I am using apache tomcat 6.0 integrated with Eclipse Europa IDE. I have a confusion. I just added the following code to my servlet to inquire about the various paths:
and I got the following output:
Context path is /ServletTest
realPath is : E:\SONNY\WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ServletTest\ServletTest\servlet\FormServlet
uri is : /ServletTest/FormServlet
path is : /FormServlet
Please explain these path terminologies and which one is used to call the servlet.
Regards
Mansukhdeep
David Newton wrote:But the servlet does *not* have that hypothetical package... and it *must* not be in the default package.
So move the servlet into a package (move the source, add the "package" declaration to the source) and update the web.xml configuration file with the new servlet class.
~ Mansukh
Virendrasinh Gohil wrote:
Mansukhdeep Thind wrote:
I am using apache tomcat 6.0 integrated with Eclipse Europa IDE. I have a confusion. I just added the following code to my servlet to inquire about the various paths:
and I got the following output:
Context path is /ServletTest
realPath is : E:\SONNY\WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ServletTest\ServletTest\servlet\FormServlet
uri is : /ServletTest/FormServlet
path is : /FormServlet
Please explain these path terminologies and which one is used to call the servlet.
Regards
Mansukhdeep
Ok. From this, it seems the simplest solution would be to change your FirstHtml.html and add or , but one more question, how did you get this output if your servlet is not receiving the request? Where did you put this code?
By the way, here goes the explanation for the return types of each method.
Context path is /ServletTest
This is the contextpath for the request. This is a relative path for request object. Which means, where is the "request" object for current request sent. This doesn't include the name of the servlet. E.g. For servlets in the default (root) context, it will returns "" as the context for this request is in Root itself.
realPath is : E:\SONNY\WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ServletTest\ServletTest\servlet\FormServlet
From my understanding, for requesting real path, you should just provide the relative path of your servlet. Instead of you should have done . This provides you where your servlet class actually resides [physical location]. This method is deprecated.
uri is : /ServletTest/FormServlet
If your application would have executed properly, you would have got http://localhost:10139/ServletTest/FormServlet
path is : /FormServlet
This returns the path for the servlet (after the context location). Assume that your servlet has package as com.example.FormServlet the output for this would be /com/example/FormServlet. This path is the location of servlet inside of your webapplication (or app context or contextpath)
In sort, typically your contextpath and servlet path combines the relative location of your servlet in Server ROOT.
I think to get better understanding on this, you should understand the terminologies used in web applications.
David Newton wrote:When you define your servlet class you have to give it the fully-qualified class name, including the package.
~ Mansukh
Sigma Infosolutions wrote:but still i am proud to be associated with Sigma Infosolutions.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |