Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet problem

 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I installed Tomcat and Apache under win 95, set up the classpath as required. sample programs in dir \webappls\examples\servlets\ run OK. I compile my HTTPGetServlet.java and put the class file in \examples\Web-inf\classes\, the .html in \examples\servlets\
The .html file as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!-- HTTPGETServlet.html -->
<HEAD>
<TITLE>Servlet HTTP GET Example</TITLE>
</HEAD>
<BODY>
<FORM ACTION = "http://127.0.0.1:8080/examples/Web-inf/classes/HTTPGetServlet"
METHOD = "GET">
<P>Click the button to have the servlet send an HTML document</P>
<INPUT TYPE = "submit" VALUE = "Get HTML document">
</FORM>
</BODY>
</HTML>
Please help,
Thanx,
Simon
 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, i forgot to point out the problem.
the error given when i press the Button "Get HTTP document":
Not Found (404)
Original request: /examples/Web-inf/classes/HTTPGetServlet
Not found request: /examples/Web-inf/classes/HTTPGetServlet
Thanx,
Simon
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"http://127.0.0.1:8080/examples/Web-inf/classes/HTTPGetServlet"
Is not the correct way to address the servlet. In fact, web servers are forbidden to directly serve any file from the WEB-INF directory. Instead, the server applies various rules to the raw URL to determine exactly what needs to be done.
"http://127.0.0.1:8080/examples/servlet/HTTPGetServlet"
should do the trick. Take a look at the example servlets and JSP provided with Tomcat to see how they are addressed. Study the web.xml file in the webapps/examples/WEB-INF directory.
Bill

------------------
author of:
 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Bill,
I got it worked. But how does the server know the location of the class file?
Thanks,
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic