My first Servlet accessed from an html page???
I am trying to access a very simple servlet called "ServletOklogin" from an html page.
But unable to do this. My webserver is tomcat.
I think it could be two problems
(1) Path incorrect in the html page
(2) Need an web.xml page
The ServletOklogin.class is located at this path:
I have the testServlet.html under the test folder, so thus the path is:
Here is the html file:
What should the path be for the "action" variable in the form??
Press the submit button:</p>
<form method="get" action="http://localhost:8080/test/servlet/ServletOKlogin">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
I have tried other variations like:
but get the error:
HTTP 404 page cannot be found???
I think the problem is I need to produce an web.xml file?????
And this would be placed in the WEB-INF folder located at:
But I do not know what should be in this file?
The book I am using does not give an example of the web.xml file I should produce????
http location ?
The location of the servlet from the html page appears correct as far as the suffix goes (test/servlet/ServletOKlogin).
You could try opening the web browser(IExplorer) and checking for the percise address of the tomcat link. At the Internet Options Connections Lan Settings. Make sure "Use a proxy server is checked with the specified address ie. 192,168.0.1 and specified port ie. 8080". Now use this address instead of the "Localhost".
Better yet, your local system may have a dns..name that you would type in place of the localhost.
Okay it works.
I have tried the same program on another pc.
I think there is something wrong with how the first pc builds new "context areas" for web applications to run.
Any way I have another question.
I have been using jsp and in jsp one could call a "jsp" from an html by entering the line below:
<form method="post" action="ServletOKlogin">
As long as the jsp and html are in the same folder. Why can't one do the same for servlets?
I'm sorry, I do not use jsps and do not know how they handle this.
Whenever you make a request to a servlet, you need to include the entire root address with the /servlet/name attached. This is because the directory the servlet sets in is different by server definition, than the directory the html code sets in.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL