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 8273197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:23:45+00:00 2026-06-08T07:23:45+00:00

I’m trying to build a Java servlet, and I’ve done everything according to the

  • 0

I’m trying to build a Java servlet, and I’ve done everything according to the instructions my prof gave our class, but I’m getting a weird error.

Background: I’m working with Java EE Helios and Tomcat 7.

I started a new dynamic web project in Eclipse, I made an index.jsp page that just gets the user’s name and sends it to the servlet, and is then supposed to print out Hello, [username]. The code is all sample code that the prof gave us and works for other people in my class.

I made a new Servlet called ServletHome and it’s in a package called servlets.

When I run the program from Eclipse, it starts up Tomcat fine, no problems. I can navigate to the index.jsp page, and it looks fine.

The problem is that when I fill in my name and press my ‘submit’ button, I get a tomcat 404 error with the message:
“The requested resource (/MyFirstServlet/ServletHome) is not available.”

Any ideas?

Thanks!!

— Edit: Code —

index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="ServletHome" method="POST">
    First Name: <input type="text" name="firstName" size="20"><br>
    Last Name: <input type="text" name="lastName" size="20"> <br>
    <br> <input type="submit" value="Submit">
</form>
</body>
</html>

ServletHome.java:

package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ServletHome extends HttpServlet {

private static final long serialVersionUID = 1L;
public ServletHome() {
    super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException 
{
}

/**
 * The function that gets the name and returns an HTML file with Hello to them
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
protected void doPost(HttpServletRequest request,
                                            HttpServletResponse response) 
throws ServletException, IOException {

    //set type of output
    response.setContentType("text/html;charset=UTF-8");

    //get writer
    PrintWriter out = response.getWriter();

    //get first name
    String firstName = request.getParameter("firstName").toString();

    //get last name
    String lastName = request.getParameter("lastName").toString();

    //write the file
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Test Title</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<p>Welcome, " + firstName + " " + lastName + "!</p>");
    out.println("</body>");
    out.println("</html>");

    out.close();
}
}

web.xml:

<?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>ServletHome</servlet-name>
            <servlet-class>servlets.ServletHome</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>ServletHome</servlet-name>
            <url-pattern>/servlets/*</url-pattern>
        </servlet-mapping>
</web-app> 
  • 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-06-08T07:23:47+00:00Added an answer on June 8, 2026 at 7:23 am

    The resource is no available because:

    1. Your action attribute is wrong, or;
    2. You didn’t map your servlet corretly. To do this, you can:

    Use @WebServlet annotation, since you are using Tomcat 7:

    @WebServlet( name = "ServletName", urlPatterns = { "/path/to/your/servlet/myName" } )
    public class ServletName extends HttpServlet {
        // your code here
    }
    

    Or map your servlet in web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" 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">
        <!-- more code here... -->
        <servlet>
            <servlet-name>ServletName</servlet-name>
            <servlet-class>yout.package.here.ServletName</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>ServletName</servlet-name>
            <url-pattern>/path/to/your/servlet/myName</url-pattern>
        </servlet-mapping>
        <!-- more code here... -->
    </web-app>
    

    Another thing that you need to pay attention is that you MUST implement the doXXX methods that corresponds to the HTTP methods (get, post, etc.) that you want your servlet to serve.

    To request this servlet through you form, you need to set the action attribute as:

    <form action="/path/to/your/servlet/myName">
        <!-- form fields here... -->
    </form>
    

    To finish, you can use the method attribute in your form to choose the HTTP method that your browser will use to request the Servlet. If you don’t provide, the default method is get. As I already said, if the get method is used, you need to implement the doGet method in the servlet.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.