Results 1 to 2 of 2
  1. #1
    anarelle's Avatar
    anarelle is offline Member
    Join Date
    Mar 2011
    Location
    Argentina
    Posts
    21
    Rep Power
    0

    Smile Absolute newbie question

    I need to call a servlet from an HTML file, but I can't get my servlet to work outside the Eclipse IDE. Something must be wrong with my paths, but I don't know what.
    I'm using Tomcat 7.0.

    This is my servlet class:
    Java Code:
    package myapp;
    public class HelloServlet extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		PrintWriter out = response.getWriter();
    		StringBuffer sb = new StringBuffer();
    		sb.append("<html><body bgcolor=pink text=black>");
    		sb.append("<h1 align=center>Hello World!</h1>");
    		sb.append("<body></html>");
    		out.println(sb);
    	}
    }
    I also have this web.xml file:
    XML Code:
    <servlet>
    	<servlet-name>HelloServlet</servlet-name>
    	<servlet-class>myapp.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    	<servlet-name>HelloServlet</servlet-name>
    	<url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    And my HTML file has a simple form like this:
    XML Code:
    <FORM METHOD=GET ACTION="HelloServlet">
    <INPUT TYPE=SUBMIT>

    Then, in my C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps folder I created a "test" folder where I placed my index.html file and a WEB-INF folder with the web.xml file and a sub-folder called "classes", where I placed HelloServlet.java and HelloServlet.class.
    I also set environment variables in my windows 7 system: CATALINA_HOME with value C:\Program Files\Apache Software Foundation\Tomcat 7.0 and CLASSPATH with value %CLASSPATH%;%CATALINA_HOME%\common\lib\servlet-api.jar;.

    With all of this, I start tomcat, open index.html and click on the submit button. All I get is a "Firefox can't find the file at /C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/test/HelloServlet" error message.
    What kind of newbie mistake am I making?

    Thanks!!!
    Last edited by anarelle; 02-26-2012 at 02:43 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Absolute newbie question

    "...and a sub-folder called "classes", where I placed HelloServlet.java and HelloServlet.class."

    Did you place the .class file (you don't need the src file), in the correct subfolder of 'classes'?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. newbie question
    By palcente in forum New To Java
    Replies: 4
    Last Post: 02-01-2012, 10:41 PM
  2. A newbie Java question
    By jeftphph in forum New To Java
    Replies: 17
    Last Post: 07-14-2011, 09:56 AM
  3. Probably a newbie question.... :P
    By gblax123 in forum New To Java
    Replies: 9
    Last Post: 02-23-2011, 10:21 PM
  4. Newbie question
    By MrNiceGuy in forum New To Java
    Replies: 8
    Last Post: 11-12-2010, 05:29 AM
  5. newbie question
    By ronguilmet in forum New To Java
    Replies: 2
    Last Post: 11-16-2009, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •