can't seem to get my java servlet to work

p;   throws ServletException, IOException  
  {  
    PrintWriter out = res.getWriter();  
 
    out.println("Hello, world!");  
    out.close();  
  }  

package test;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;

public class HelloServlet extends HttpServlet {
  public void doGet (HttpServletRequest req,
                     HttpServletResponse res)
    throws ServletException, IOException
  {
    PrintWriter out = res.getWriter();

    out.println("Hello, world!");
    out.close();
  }
}

I would greatly appreciate any help; I can't think of anything else to look at. I'm pretty sure my JAVA_HOME variable has been set correctly.
I assume that your web app is rooted at webapps/hello in the Tomcat folders?

Have you verified that the app has been deployed via Tomcat's manager application?

Have you gone through the steps shown in the ServletsFaq to debug?

I'm not sure what actually qualifies as my 'web app', or what Tomcat's manager application is.

This is my folder hierarchy: '/var/lib/tomcat7/webapps/hello/WEB-INF/classes/test'.
'WEB-INF' contains my web.xml.
'test' contains my HelloServlet.class, HelloServlet.java, and HelloServlet.java.save, though I'm not sure where the .java.save came from.
I also have a war file in both my webapps and hello directory b/c I wasn't sure where exactly it was supposed to go.

I wasn't aware of the ServletsFaq; I'll take a look at it.
My JAVA_HOME environment variable is currently set at '/usr/bin/jvm/java-openjdk'.


Posts: 32
 posted 2013年7月2日 4:31:51   0  
Thank you for those clarifications. They were helpful. Near as I can tell, I'm doing all of them.
I've now changed my web.xml to the following, changing the servlet-path a bit:

view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
<web-app version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
 xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemalocation=  
"http:/java.sun.com/dtd/web-app_2_3.dtd">  
        <servlet>  
                <servlet-name>hello</servlet-name>  
             &nbs

Back  [1] [2] [3] Next

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright