Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

calling a simple servlet from an html page???

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to access a very simple servlet called "ServletOklogin" from an html page.
But unable to do this.
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:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\classes
I have the testServlet.html under the test folder, so thus the path is:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\test
Here is the html file:
[code]
<html>
<head>
<title>testServlet.html</title>
</head>
<body>
<p>Press the submit button:</p>
<form method="get" action="http://localhost:8080/test/servlet/ServletOKlogin">

<p>
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<p> </p>
</body>
</html>
What should the path be for the "action" variable in the form??
I have tried other variations like:
"test/WEB-INF/classes/ServletOKlogin"
etc.
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:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\ ???
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???
Please help???
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey sid,
if you want to connect from a html page to a servlet you don`t need a web.xml file.
the only thing you had to do is to start tomcat, before calling the html page and to set the right pass to your servlet.
i`ve wrote a little html page that connect to a servlet and the correct path is:
< form action="http://localhost:8080/examples/servlet/Coffees4" method="get" />
infact the examples folder is a default folder from tomcat and i have my .java and .class files in it.
the html file should be whereever it will be, doesn`t matter.
hope this may help you.
bernd
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
bernd pier
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey sid,
did you want to call a servlet from a html page?
the code for this is:
<form action="http://localhost:8080/examples/servlet/servletname" method="get">....
so the html page could be anywhere on your pc, cause you refer via localhost:8080 to tomcat/examples directory.
good luck
bernd
 
machines help you to do more, but experience less. Experience this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic