Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:48:00+00:00 2026-05-28T18:48:00+00:00

this is my first servlet ever. here is it’s code. import javax.servlet.*; import javax.servlet.http.*;

  • 0

this is my first servlet ever. here is it’s code.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    PrintWriter out = response.getWriter();
    java.util.Date today = new java.util.Date();
    out.println("<html> " +"<body>" +"<h1 align=center>HF\'s Chapter1 Servlet</h1>" +" " + "<br>" + today + "</body>" + "</html>");
    }
}

I compiled it using this command
javac -classpath /usr/share/tomcat7/common/lib/servlet-api.jar -d classes src/Ch1servlet.java
I then put the .class file in the classes folder in my WEB-INF folder.

Here is my web.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<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 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>Chapter1 Servlet</servlet-name>
        <url-pattern>/Serv1</url-pattern>
    </servlet-mapping>
</web-app>

Tomcat7 keeps giving me a 404 on http://127.0.0.1:8080/ch1/Serv1/ saying The requested resource (/ch1/Serv1/) is not available.

File Tree:
File Tree

What am i doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:48:02+00:00Added an answer on May 28, 2026 at 6:48 pm

    You should put servlet classes in a package. Whether packageless servlets works depend on the specific combination of an older Tomcat and JVM version. If you see this example in a book/tutorial, then it is surely far outdated.

    package com.example;
    
    // ...
    
    public class Ch1Servlet extends HttpServlet {
        // ...
    }
    

    You should have a /com/example/Ch1Servlet.java file. Compile it as follows

    javac -classpath /usr/share/tomcat7/common/lib/servlet-api.jar -d classes src/com/example/Ch1servlet.java
    

    (I however wonder what the common lib is doing there, this was typical for Tomcat 4.x/5.x, but it’s not present since Tomcat 6. If you manually changed Tomcat’s structure in order to follow the instructions of an outdated tutorial, undo it!)

    Put the com folder with the generated class by its entirity in /WEB-INF/classes folder of your webapp. So you must have a /WEB-INF/classes/com/example/Ch1Servlet.class.

    Then, edit your /WEB-INF/web.xml to specify the fully qualified name (FQN) of the servlet class in <servlet-class>:

    <?xml version="1.0" encoding="UTF-8"?>
    <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_3_0.xsd"
        version="3.0" 
    >
        <servlet>
            <servlet-name>Chapter1 Servlet</servlet-name>
            <servlet-class>com.example.Ch1Servlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>Chapter1 Servlet</servlet-name>
            <url-pattern>/Serv1</url-pattern>
        </servlet-mapping>
    </web-app>
    

    (please note that I fixed the root declaration as well to comply Tomcat 7 supported servlet version, it would otherwise fall back to least compatibility modus)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code first: '''this is main structure of my program''' from twisted.web import http from
Suppose somewhere I import javax.servlet.http.HttpServlet . My questions: Does this mean: I could find
Saw this piece of code in a Ruby on Rails book. This first one
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a
This is my first Portlet. I am not getting values inside my servlet. Please,
I've just created my first Java EE servlet using Hibernate. What I don't know
This is my second try to solve this problem. My first try was here
This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo
problem euler #5 i found the solution but i don't know why this first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.