title: In Tomcat6.0 "The requested resource () is not available." occurred
body: <p>Yesterday I encountered one problem when programming with java servlet on remote server.</p>
  
  <p>Our assignment is to build a simple shopping cart and user can add items by typing the name and clicking "submit", then servlet will be invoked and show the items purchased.</p>
  
  <p>After I coded it, the server tells me error with "The requested resource () is not available." every time. I searched and tried all methods I could find but still not work.</p>
  
  <p>Here are the codes:</p>
  
  <p>HTML(/~usr/public_html/market.html)</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Online Shopping&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;Online Shopping&lt;/h1&gt;
  Welcome to the online market!&lt;br&gt;
  &lt;br&gt;
  Please input the item you want to buy:&lt;br&gt;
  &lt;form action="http://localhost:8080/~usr/cart" method="get"&gt;
  &lt;input type="text" name="item"&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml(/~usr/public_html/WEB-INF/web.xml)</p>
  
  <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5"&gt;
  &lt;servlet&gt;
  &lt;servlet-name&gt;cart&lt;/servlet-name&gt;
  &lt;servlet-class&gt;cart&lt;/servlet-class&gt;
  
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;cart&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/cart&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Java Code(compiled and put it to /~usr/public_html/WEB-INF/classes/cart.class)</p>
  
  <pre><code>import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.util.*;
  import java.io.*;
  
  
  public class cart extends HttpServlet
  {   
      public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
      {
          res.setContentType("text/html");
          PrintWriter out = res.getWriter();
  
          HttpSession session = req.getSession(true);
  
          //get the previous number of items in cart. If none, creat it and initialize to zero
          Integer count = (Integer)session.getAttribute("count");
          if(count == null)
              count = new Integer(0);
  
          //declare a string reference to get the new added item, if it's null, don't add it
          String[] item_name;
  
          item_name = req.getParameterValues("item");
          if(item_name != null)
          {           
              count ++;
              session.setAttribute("count",count);    
              session.setAttribute("items"+count,item_name[0]);
          }
  
              out.println("&lt;html&gt;");
              out.println("&lt;head&gt;");
              out.println("&lt;title&gt;Items in Shopping Cart&lt;/title&gt;");  
              out.println("&lt;/head&gt;");
              out.println("&lt;body&gt;");
              out.println("New item successfully added to shopping cart.&lt;br&gt;");
              out.println("Your cart contains X items.&lt;br&gt;&lt;br&gt;");
              out.println("&lt;center&gt;&lt;h1&gt;The items you purchased:&lt;/h1&gt;");
  
              for(int i=1; i&lt;=count; i++)
                  {
                      String goods = (String)session.getAttribute("items"+i);
                      out.println("Item #"+i+": "+goods+"&lt;br&gt;");
                  }
  
  
              out.println("&lt;/center&gt;&lt;/body&gt;");
              out.println("&lt;/html&gt;");
  
              out.close();
      }
  
  
  
  }
  </code></pre>
  
  <p>Tomcat and server are configured beforehand by professor and I just followed the rules where to put these files and so on. </p>