DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2002
    Posts
    22

    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:
    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>
    
    
    
    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>
    </form>
    
    
    </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???

  2. #2
    Join Date
    Oct 2002
    Posts
    4

    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.

  3. #3
    Join Date
    Aug 2002
    Posts
    22
    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?

  4. #4
    Join Date
    Oct 2002
    Posts
    4

    servlet functioning

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links