Results 1 to 13 of 13

Thread: Requested Resource was not found?

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Requested Resource was not found?

    I finally got my classpath and everything set up for j2ee. Now I'm running into a problem whenever I try to run tomcat, and then try to run the servlet. It says "The requested resource is not available".

    I typed this in as the URL: http://localhost:8080/ch1/Serv1

    Here is the java code:
    Code:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    public class Ch1Servlet extends HttpServlet
    {
    	public void doGet(HttpServletRequest request, HttpServletResponse response)
    	{
    		try
    		{
    			PrintWriter out = response.getWriter();
    			java.util.Date today = new java.util.Date();
    			out.println("<html>" +
    				 	"<body>" +
    					"<h1 align=center>Chapter 1 Servlet></h1>" +
    					today.toString() +
    					"</body>" +
    				    "</html>");
    		}
    		catch(IOException ioe)
    		{
    			ioe.printStackTrace();
    		}
    	}
    }
    XML Code..Although I have no clue what it's for, and what I wrote:
    Code:
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    	web-app_2_4.xsd"
    	version="2.4">
    	
    	<servlet>
    		<servlet-name>Chapter1 Servlet</servlet-name>
    		<servlet-class>Ch1Servlet</servlet-class>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>Chapther1 Servlet</servlet-name>
    		<url-pattern>/Serv1</url-pattern>
    	</servlet-mapping>
    </web-app>

    Please help me out!

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Requested Resource was not found?

    First off, where are you saving the codes? Is it in the %CATALINA_HOME%/webapps/ROOT? All you need is, to add the Ch1Servlet.class in %CATALINA_HOME%/webapps/ROOT/WEB-INF/classes and just access it using http://localhost:8080/servlet/Ch1Servlet.

    Now, you have a web.xml you are talking... So I assume you're saving your java files and the Ch1Servlet.class somewhere in your hard drive. See http://vbforums.com/showthread.php?t=337553 and lemme know what you'll find out.

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    I can't even get it to run when I put it in the default directory like you said. I did have my own directory like this:
    Code:
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\Web.xml
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\classes\Ch1Servlet.java
    I updated my XML file to look like yours:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
         PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    	<servlet>
    		<servlet-name>Ch1Servlet</servlet-name>
    		<servlet-class>Ch1Servlet</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>Ch1Servlet</servlet-name>
    		<url-pattern>/Ch1Servlet</url-pattern>
    	</servlet-mapping>
    </web-app>
    Then I ran the server, and typed this in:

    http://localhost:8080/Ch1Servlet/Ch1Servlet

    I also added the Context tag in the server.xml file.

    Thanks for the help you've given me neb. I've tried several forums, including the java.sun forum, but they aren't very nice people. I've searched the web for almost three days now, and I can't find nothing. I bought this book called Head First Servlets and JSP, but it's for certification and doesn't teach from the ground up. If you don't mind, along with helping me with this, could you post some good tutorials?

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Requested Resource was not found?

    Here's what I've done testing your code. Project folder is in
    VB Code:
    1. %CATALINA_HOME%/webapps/ch1
    2.                           + WEB-INF
    3.                                   + classes
    4.                                       + Ch1Servlet.class
    5.                                   + src
    6.                                       + Ch1Servlet.java
    7.                           + web.xml
    I'm sorry about my web.xml, it was 2.3 specification. Yours is the new one. Inside it btw, is
    VB Code:
    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
    5.     version="2.4">
    6.    
    7.     <servlet>
    8.         <servlet-name>Chapter1 Servlet</servlet-name>
    9.         <servlet-class>Ch1Servlet</servlet-class>
    10.     </servlet>
    11.    
    12.     <servlet-mapping>
    13.         <servlet-name>[color=red]Chapter1 Servlet[/color]</servlet-name>
    14.         <url-pattern>/Serv1</url-pattern>
    15.     </servlet-mapping>
    16. </web-app>
    Note that I colored it red, servlet-name should match the servlet-name mapped. Yours is misspelled. Now, edit your %CATALINA_HOME%/conf/server.xml and add the Context path,
    VB Code:
    1. . . .
    2. <Context path="/ch1" reloadable="true" docBase="C:\java\tomcat\tomcat 5.5\webapps\ch1" />
    3.  
    4.       </Host>
    5.  
    6.     </Engine>
    7.  
    8.   </Service>
    9.  
    10. </Server>
    ch1 now is our path which we access by http://localhost:8080/ch1 and the document base is your %CATALINA_HOME%/webapps/ch1. I have a different location on my tomcat installation so you should change it to point in your ch1 project.

    Back in server.xml, we have our servlet-name Chapter 1 Servlet mapped as Serv1 so accessing it by http://localhost:8888/ch1/Serv1 will display your Ch1Servlet servlet.

    Btw, I don't have good online tutorials on this stuff. I have our Tomcat book here by Wrox (Wrox - Professional Apache Tomcat 5) and Core-Servlets-and-JSP O'Reilly. I can't mail them though, 10.+ MB and 11.+ MB are the sizes respectively.

    Edit: You are correct saying java.sun.com forums aren't nice people. I was there. Hehehe.
    Last edited by nebulom; May 29th, 2005 at 09:32 PM.

  5. #5

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    I followed everything, and it still didn't work. There has to be something simple, or something to this new version of tomcat that's stopping me. Do you think I should place the servlet in a package? If so, I would change the <servlet-classname> tag to something like this:

    <servlet-classname>Package.Filename</servlet-classname>

    Is that correct?

    By the way, thank you SOOO much for the help so far. Not many people would be willing to offer the amount of help you have. I wish there was some other way I could thank you besides a simple thanks, and added reputation.

  6. #6

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    I think there is something I need to mention. Everytime I try to install Tomcat 5.5, I get this error message in the middle saying Tomcat 5.5 service could not be installed, do you wish to ignore? I always click yes to it.

  7. #7

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    I'm switching to tom 4 right now. I'll set that up and see how it goes. I've been reading on the internet that a lot of people are having problems with tom 5.5, and it's recomended to stay with 5, or 4.

  8. #8

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    Ok, it worked with tomcat 4.1. I guess that means that it was just the version. Sorry for putting you through so much trouble, I know it was getting annoying.

    Anyways, I was wondering if you could help me with one more thing...
    What do the lines in bold/red mean?

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
         PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    	<servlet>
    		<servlet-name>webtest</servlet-name>
    		<servlet-class>webtest</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>webtest</servlet-name>
    		<url-pattern>/webtest</url-pattern>
    	</servlet-mapping>
    </web-app>

  9. #9
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Requested Resource was not found?

    I don't know much about XML so I can't help you explaining that thing. It's Document Type Definition that Suns pre-defined. Check http://www.w3schools.com/dtd/default.asp for more details. I'm sorry can't help much.

    Btw, it's ok (you're not a bother or something)... Keep it up.

    Edit: Also check http://java.sun.com/dtd/web-app_2_3.dtd to check the definition.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Requested Resource was not found?

    Had you actually compiled the .java file? It doesn't happen automatically.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Requested Resource was not found?

    Also, setting a Context path needs a restart on Tomcat (I could be wrong).

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Requested Resource was not found?

    It does. Any change to server.xml does, unless done via the Administration servlet.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Requested Resource was not found?

    I did compile the source code, and placed it in the correct directory and everything too. I also set the classpath to the servlet api file, and it still didn't work and I changed it when I installed the later version of Tomcat. I did read on the internet that a lot of people were having trouble with 5.5, and they called it "uncharted territory", and shouldn't use it unless you want to sort out all the problems. I would like to use 5.5, but I don't want to deal with all that mess again. I believe I might email apache and ask them, or check out there documentation to see what the problem is.

Posting Permissions

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



Click Here to Expand Forum to Full Width